Jump to content

sorting while results


rvdb86

Recommended Posts

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

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  ???

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.