Page 1 of 1

How to create a database of "files in the folder"?

Posted: Sun Nov 09, 2008 10:55 am
by lgmcben
I'm trying to:

1. upload (say, 100 images) to a folder.
2. Create a database of that 100 images. (which contains something like name, artist, etc.)

Could anyone please give me a guidance on how to do this with PHP please? (only for step 2. I can just use ftp for step 1)

Thank you in advance.

Re: How to create a database of "files in the folder"?

Posted: Tue Nov 11, 2008 11:03 pm
by novice4eva
lets say your pictures are in directory pics/ then:

Code: Select all

 
$dir = 'pics/';
if (is_dir($dir)) 
{
   if ($dh = opendir($dir)) 
   {
       while (($file = readdir($dh)) !== false) 
       {
            if(!(strcmp($file,'.')==0 || strcmp($file,'..')==0))
            {
                    $content = file_get_contents($dir.$file);/*YOUR PICTURE IS HELD IN THIS VARIABLE, BUILD SQL TO INSERT THIS INTO THE TABLE*/
 
            }
       }
       closedir($dh);
   }
}