Support Forums

Full Version: PHP echo contents of folder help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok i have a folder i use to upload images among other things.
Now i want a script to allow me and a select few others to view the contents and click on the file name to load the image or whatever.
I have that working largely however i cant seem to get it to link to the file.
Now im not going to post the vb hooks as there is no need however the below is the code i am using to sort the folder and display its contents.
Its doing that ok. Displaying based on time stamp however i cant get the linking to work properly. I get the link with an array at the end.
Here is the code for anyone that can help.
Also if you see other issues please let me know.
Me and coding dont go well together.
Im more of a porn man Pirate

PHP Code:
<?php
   $path 
$_SERVER[DOCUMENT_ROOT]."XXXXXXXXXXXX";
   
$dh = @opendir($path);

   while (
false !== ($file=readdir($dh)))
   {
      if (
substr($file,0,1)!=".")
         
$files[]=array(filemtime($path.$file),$file);   
   }
   
closedir($dh);

   if (
$files)
   {
      
rsort($files); #sorts by filemtime

      
foreach ($files as $file)
         echo
"<a href=http://www.MY URL HERE/$file>$file[1]</a><br>\n";  #file[0]=Unix timestamp; file[1]=filename
   
}
?>

Thanks if anyone can help.

Fixed it. I was calling up the timestamp instead of the file for the link reference lol.
Man im useless at this.
Glad you found your area of mistake.
Next time I'd say go to HF, they have more people to help you trust me.
I hate seeing threads blank when it's supposed to be SupportForums.
You are calling the file from the url. Unless your files are in your root web directory, it won't work. Make sure you append the document root to the url link.
This has been resolved a long time ago but thanks for the replies.