rvdb86 Posted February 16, 2009 Share Posted February 16, 2009 hi, i have the following function that produces a list of files on the server. It shows the filename, file size and the date the file was created. Maybe some one could help me figure out how to sort these results by the previously mentioned parameters? <?php function ListFolder($path) { //using the opendir function $dir_handle = @opendir($path) or die("Unable to open $path"); //Leave only the lastest folder name $dirname = end(explode("/", $path)); //display the target folder. //echo ("<li>$dirname\n"); //echo "<ul>\n"; while (false !== ($file = readdir($dir_handle))) { if($file!="." && $file!="..") { if (is_dir($path."/".$file)) { //Display a list of sub folders. ListFolder($path."/".$file); } else { $size = filesize($path."/".$file); $sizemb = ($size / 1024)/1024; $sizemb = round($sizemb,2); $ext = substr($file, strrpos($file, '.') + 1); $temp_file = $string = substr($file, 0, -4); //DATE FILE WAS ADDED: $filedate = date ("d.m.y", filemtime($path."/".$file)); $check = ($i % 2); if ($check == 1) { $bgcolor = "#FFFFFF"; }else{ $bgcolor = "#eeeeee"; } //$type = filetype($path."/".$file); // file //Display a list of files. echo "<tr bgcolor=\"$bgcolor\">"; echo "<td>"; echo "<img src=\"images/$ext.gif\" border=\"0\" alt=\"\">"; echo "</td>"; echo "<td colspan=\"2\">"; echo "$temp_file"; echo "</td>"; echo "<td>"; echo $sizemb . "mb"; echo "</td>"; echo "<td>"; echo $filedate; echo "</td>"; echo "<td>"; echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">"; echo "<input type=\"hidden\" name=\"path\" value=\"".$path."/".$file."\">"; echo "<input type=\"hidden\" name=\"delete_file\" value=\"1\">"; echo "<input type=\"image\" src=\"images/Delete.png\" border=\"0\" alt=\"Delete File\" name=\"delete_file\" onClick=\"return confirmSubmit()\">"; echo "</form>"; echo "</td>"; echo "</tr>"; } } $i++; } //closing the directory closedir($dir_handle); } ?> Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/145430-sorting-while-results/ Share on other sites More sharing options...
Brian W Posted February 16, 2009 Share Posted February 16, 2009 you should make an array of the files and thier info first than use array functions to sort the results http://us.php.net/manual/en/book.array.php then simply output using a foreach loop or something once you've sorted them... Link to comment https://forums.phpfreaks.com/topic/145430-sorting-while-results/#findComment-763442 Share on other sites More sharing options...
printf Posted February 16, 2009 Share Posted February 16, 2009 When do you want to sort, (in each directory) or just all the files at one time? Link to comment https://forums.phpfreaks.com/topic/145430-sorting-while-results/#findComment-763453 Share on other sites More sharing options...
rvdb86 Posted February 16, 2009 Author Share Posted February 16, 2009 all the files, not using directories Link to comment https://forums.phpfreaks.com/topic/145430-sorting-while-results/#findComment-763462 Share on other sites More sharing options...
rvdb86 Posted February 16, 2009 Author Share Posted February 16, 2009 am i on the right track here? i changed my code as follows: function ListFolder($path) { //using the opendir function $dir_handle = @opendir($path) or die("Unable to open $path"); //Leave only the lastest folder name $dirname = end(explode("/", $path)); //display the target folder. //echo ("<li>$dirname\n"); //echo "<ul>\n"; while (false !== ($file = readdir($dir_handle))) { if($file!="." && $file!="..") { if (is_dir($path."/".$file)) { //Display a list of sub folders. ListFolder($path."/".$file); } else { $size = filesize($path."/".$file); $sizemb = ($size / 1024)/1024; $sizemb = round($sizemb,2); $ext = substr($file, strrpos($file, '.') + 1); $temp_file = $string = substr($file, 0, -4); //DATE FILE WAS ADDED: $filedate = date ("d.m.y", filemtime($path."/".$file)); $check = ($i % 2); if ($check == 1) { $bgcolor = "#FFFFFF"; }else{ $bgcolor = "#eeeeee"; } $filename[$i] = $temp_file $filesize[$i] = $sizemb $filedate[$i] = $filedate } } $i++; } //closing the directory closedir($dir_handle); } how i just need some help with the script that would sort these arrays ??? Link to comment https://forums.phpfreaks.com/topic/145430-sorting-while-results/#findComment-763478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.