Jump to content

Creating index of all the file names in a dir under a mysql file_name column...


Recommended Posts

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!

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

 

 

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>";
}

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>";
}

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.