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. :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.