Click to See Complete Forum and Search --> : Need help with auto creating links to files in a fodler


BWWebDesigns
09-13-2006, 08:32 PM
hi there

im looking for a little help with php and this is what i require

lets say i have a folder of what ever name and i have an index file in this folder along with several zip files

i am looking for info/script/code ideas on how i would using php on the index page for it to automatically detect the zip files in the folder it is in and to take the name of each file and create a link to the file

so every time i upload a new zip file to that fodler the index page would automatically show a link to it using the name of the file

same if i delete any of the zip files

im trying to make it quicker on me rather than having to manually type download links into each index file in each folder, if they could create them on the fly for me depending on the zip files located in their respective folders it would save me hours of work

thanks in advance to anyone who offers helpful code or even better a complete solution ;)

pcthug
09-13-2006, 09:18 PM
I haven't tested it yet but it should work.

// put this in your index file
if ($handle = opendir(dirname(__FILE__))) {

while (false !== ($filename = readdir($handle))) {
if ($filename != "." && $filename != ".." && basename($filename) != basename($_SERVER['PHP_SELF'])) {
echo "<a href=\"$filename\">" . basename($filename) . "<br />\n";
}
}

closedir($handle);
}

BWWebDesigns
09-13-2006, 09:22 PM
thanks ill test it and see

will this also detect the index file aswell?? or just the zip files??

BWWebDesigns
09-13-2006, 09:26 PM
ok never mind i see that it doesnt

i made a modification you had missed off the </a> close tag for the link

other than that it works perfectly

thanks so much

BWWebDesigns
09-13-2006, 09:34 PM
quick question

what if i wanted it to check a folder with the folder that the index file is located in instead of that folder itself??

Never mind I just figured it out

thanks anyway