KingOfHeart Posted March 19, 2010 Share Posted March 19, 2010 I want to list all the folders and files. Folders need to be listed first, then files. I want to use $_GET to let me choose the directory. I want to see the name, last modified time. Can you help? Link to comment https://forums.phpfreaks.com/topic/195752-list-folders-and-files/ Share on other sites More sharing options...
teamatomic Posted March 19, 2010 Share Posted March 19, 2010 All you have to do is turn this into a function and add the file info. It also display icons of the file type. I've attached them just in case. <style> a { color:blue; font-size:10pt; text-decoration:none; font-weight:400; font-family:verdana, arial, helvetica, sans-serif; padding:0px 0px 0px 0px; } a:visited {color:#4020e0;} a:hover {color:blue;font-weight:400;} a:active {color:yellow;} </style> <table width="100%"><tr><td colspan=3 align=center> <?php $dir = '/home'; echo "<h3>Index of $dir</h3>" ?> </td><tr><td width="25%"></td><td valign="top"> <?php $arraydir=array(); $arrayfile=array(); $files = scandir($dir); natcasesort($files); //$files=natsort($files); foreach ($files as $file) { if ($file != "." && $file != "..") { if(is_dir($file)) { array_push($arraydir,$file); } else { array_push($arrayfile,$file); } } } echo "files<br>"; foreach($arrayfile as $file) { list($xxx,$ext)=explode(".",$file); trim($ext); echo "<img src=\"./images/$ext.png\" /><a href=\"$file\">$file</a><br>\n"; } echo "<P>"; echo "</td><td valign=\"top\">directories<br>"; foreach($arraydir as $file ) { echo "<img src=\"./images/folder.png\" border=0><a href=\"$file\">$file</a><br>\n"; } //print_r($files); ?> </td></tr></table> HTH Teamatomic [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/195752-list-folders-and-files/#findComment-1028355 Share on other sites More sharing options...
KingOfHeart Posted March 21, 2010 Author Share Posted March 21, 2010 Works great. What about file modified time? Link to comment https://forums.phpfreaks.com/topic/195752-list-folders-and-files/#findComment-1029360 Share on other sites More sharing options...
teamatomic Posted March 21, 2010 Share Posted March 21, 2010 Look around line 50 and change it to this $file_mod = date("m/d/Y h:i a",filemtime("$file")); echo "<img src=\"./images/$ext.png\" /><a href=\"$file\">$file $file_mod</a><br>\n"; HTH Tteamatomic Link to comment https://forums.phpfreaks.com/topic/195752-list-folders-and-files/#findComment-1029361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.