Support Forums
PHP echo contents of folder help - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: PHP echo contents of folder help (/showthread.php?tid=26079)



PHP echo contents of folder help - DAMINK™ - 04-25-2012

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.


RE: PHP echo contents of folder help - Deity - 05-29-2012

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.


RE: PHP echo contents of folder help - Prefinem - 06-01-2012

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.


RE: PHP echo contents of folder help - DAMINK™ - 06-01-2012

This has been resolved a long time ago but thanks for the replies.