membot Posted September 17, 2011 Share Posted September 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247322-a-way-to-add-rows-to-a-table-for-each-file-in-a-folder/ Share on other sites More sharing options...
sunfighter Posted September 19, 2011 Share Posted September 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247322-a-way-to-add-rows-to-a-table-for-each-file-in-a-folder/#findComment-1270716 Share on other sites More sharing options...
fenway Posted September 20, 2011 Share Posted September 20, 2011 Yup, just missing the actual INSERT. Quote Link to comment https://forums.phpfreaks.com/topic/247322-a-way-to-add-rows-to-a-table-for-each-file-in-a-folder/#findComment-1271066 Share on other sites More sharing options...
dmirsch Posted September 20, 2011 Share Posted September 20, 2011 I can use this...however, is there a way to modify it so that if there are subdirectories, it will list those as hyperlinks so the code would run off of those if you were to click that link? Quote Link to comment https://forums.phpfreaks.com/topic/247322-a-way-to-add-rows-to-a-table-for-each-file-in-a-folder/#findComment-1271137 Share on other sites More sharing options...
fenway Posted September 20, 2011 Share Posted September 20, 2011 Clicking links has nothing to do with mysql. Quote Link to comment https://forums.phpfreaks.com/topic/247322-a-way-to-add-rows-to-a-table-for-each-file-in-a-folder/#findComment-1271146 Share on other sites More sharing options...
membot Posted September 22, 2011 Author Share Posted September 22, 2011 Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/247322-a-way-to-add-rows-to-a-table-for-each-file-in-a-folder/#findComment-1271818 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.