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

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
lgmcben
Forum Newbie
Posts: 2
Joined: Sun Nov 02, 2008 12:54 pm

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

Post 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.
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

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

Post 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);
   }
}
 
Post Reply