cgm225 Posted February 6, 2008 Share Posted February 6, 2008 I have a directory full of jpg's, and I want to create list/index of those file names, in alphabetical order, in an "images" table in MySQL, under a "file_name" column. I don't want to have to manually enter each file name, and wanted to know if someone would help me create a script (possibly with a loop?), to do this automatically? Any ideas? Thank you all in advance! Quote Link to comment https://forums.phpfreaks.com/topic/89778-creating-index-of-all-the-file-names-in-a-dir-under-a-mysql-file_name-column/ Share on other sites More sharing options...
amites Posted February 6, 2008 Share Posted February 6, 2008 there are some good codes to get started with in the code snippet library at http://www.phpfreaks.com easy to find a script to read directory contents, from there putting it into a DB is fairly simple, after you've tried to build something yourself you'll find more help available Quote Link to comment https://forums.phpfreaks.com/topic/89778-creating-index-of-all-the-file-names-in-a-dir-under-a-mysql-file_name-column/#findComment-460146 Share on other sites More sharing options...
cgm225 Posted February 8, 2008 Author Share Posted February 8, 2008 bump - I still have not found a good code snippet for this, and wanted to know if someone could help me? Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/89778-creating-index-of-all-the-file-names-in-a-dir-under-a-mysql-file_name-column/#findComment-462032 Share on other sites More sharing options...
legohead6 Posted February 8, 2008 Share Posted February 8, 2008 heres mine... just change $dir to your directory.. $dir = "members/$userfolder"; $dh = @opendir($dir); //get files in the folder while (false !== ($filename = @readdir($dh))) { $files[] = $filename; } $re = array_search('..', $files); $rem = array_search('.', $files); unset($files[$rem], $files[$re]); $totalp = count($files); //if not in a folder, the show upload and creat folder stuff if(empty($_GET['f'])){ echo "<div align=center><table><tr><td colspan=4>$uploader</td></tr><tr><td colspan=3>$foldermaker<tr><td colspan=3><hr></td></tr><tr><td colspan=3><p align=center><u>Current Folders</u></p></td></tr>"; }else{ //show link to get back to main folder echo "<div align=center><table><tr><Td colspan=4><p align=center><a href=account.php>Up One Level</a></p></td></tr>"; } Quote Link to comment https://forums.phpfreaks.com/topic/89778-creating-index-of-all-the-file-names-in-a-dir-under-a-mysql-file_name-column/#findComment-462043 Share on other sites More sharing options...
legohead6 Posted February 8, 2008 Share Posted February 8, 2008 CORRECTED, IGNORE ABOVE $dir = "members/$userfolder"; $dh = @opendir($dir); //get files in the folder while (false !== ($filename = @readdir($dh))) { $files[] = $filename; } $re = array_search('..', $files); $rem = array_search('.', $files); unset($files[$rem], $files[$re]); $totalp = count($files); foreach($files as $id => $file){ $folder1=explode('.',"$file"); $file1 = str_replace(" ", "_", "$file"); $file2 = str_replace(".", ".", "$file1"); $file3 = @str_replace("_"," ", "$file"); echo "<tr><td bgcolor=#B4B4B4><p align=center><a href=\"#\" onClick=\"poptastic('doc.php?f=$doc');\">$file3</p></td><td bgcolor=#B4B4B4>"; echo "<a href=move.php?f=$doc&fo=$folde>Move File</a></td><td bgcolor=#B4B4B4><a href=move.php?f=$doc&d=1>Delete File</a></td><td bgcolor=#B4B4B4><a href=sfile.php?f=$doc>Send File</a></td></tr>"; } Quote Link to comment https://forums.phpfreaks.com/topic/89778-creating-index-of-all-the-file-names-in-a-dir-under-a-mysql-file_name-column/#findComment-462048 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.