Jump to content

A way to add rows to a table for each file in a folder?


membot

Recommended Posts

I have a MySQL table for some photos (including columns like file path, caption, date, etc.), and I'm eventually making a PHP form I can use to upload photos and set the captions and whatever.

 

However, initially, I want to add around 100 photos, and I'm thinking it would be easier to upload them all by FTP and have some kind of script (which I would only use this once) that would add all the photos in that folder to the MySQL table. Only the file path column would need to be filled out with this.

 

I'm thinking this might not necessarily be a MySQL command or a PHP script, but I don't know anything about any other programming languages. Any help is appreciated. :)

After you copy your file with FTP use this:

<?php

$handle = opendir('PUT NAME OF YOUR DIR HERE');
while (false !== ($file = readdir($handle)))
{
    if ($file != "." && $file != "..")
{
        echo $file,'<br />';
    }
}
closedir($handle);
?>

 

It will list your files so you can check that it is correct. It list them without the . and .. that are in dir's.

 

Then change the echo line to write file names and path into your DB.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.