using PHP script to add address'es of all picture files in a dir to MYSQL DB

From: Date: Tue, 06 Nov 2001 12:12:55 +0000
Subject: using PHP script to add address'es of all picture files in a dir to MYSQL DB
Groups: php.general 
Request: Send a blank email to php-general+get-73575@lists.php.net to get a copy of this message
Hi, I want to make a simple database driven photo gallery for my site where users can search the picture descriptions to find the pictures they want, all fairly simple PHP/MySQL stuff which I know. My big problem is that I have like 500+ images I want to put into the MySQL DB and I am way too lazy to consider doing it the hard way. I was wondering if it would be possible to write a PHP script which would get a list of all the .jpg files in its current directory and then insert a reference for each file (basically just its location on the web server) into the MySQL PHOTO table? I was thinking about this on the train yesterday so heres the pseudo PHP/C code of the sort of script I was thinking about(I don't know the PHP file functions): //get the number of jpeg files in same dir as this script (I don't know code for this) $NumFiles = GetNumberOfJPGFilesInDirectory(); While ($NumFiles > 0) { //get file location of current jpeg file (I don't know code for this) $FileName = GetFileNameAndLocation($NumFiles); // construct MySQL query $sql = "INSERT INTO PHOTO SET " . "FILE='$FileName "; //add file location of current jpeg and do error handling (easy stuff) if (mysql_query($sql)) { echo("Photo " . $FileName ." has been added.<br>"); }else { echo("Error adding photo: " . mysql_error() . " <br>"); } $NumFiles = $NumFiles-1; } Would anyone be able to help me get the code for this script right? I can do basic PHP & MySQL stuff but I am not familiar with PHP file functions so I need someone to help me get it working... Cheers, Daniel

« previous php.general (#73575) next »