I have tried looking in the forum and cant seem to find anything similar. I am a student but still a newb to php and would GREATLY appreciate anyone who could help a man out...
I need to sort the files by date modified but currently is in an array sorted by the name of the file which I dont need.
Heres a snipit of the code below to give you an idea of where I think I need to alter things but dont know where to begin. (I have tried natsort() but dosnt work for what i need.
// If a note exists, read in the data
if (file_exists($dir . $note) == TRUE)
{
$fp = fopen($dir . $note, "r");
$notes = fread($fp, filesize($dir . $note));
fclose($fp);
}
// Loop through all files and directories and
// place them in their respective arrays.
while($entry = readdir($handle))
{
if (is_dir($entry) && $entry != ".")
{
// Determine if the folder should be hidden
if ($entry == "..")
{
// Make sure that the back link isn't hidden
$subdirs_array[] = $entry;
}
else if ($hide_dot == FALSE || ($hide_dot == TRUE && ereg("^\.", $entry) == FALSE))
{
$subdirs_array[] = $entry;
}
}
else if ($entry != ".." && $entry != ".")
{
// Delete any lock files if needed
if (ereg("\.fileman$", $entry) == TRUE && $edit_lock == TRUE)
{
// Check to see if the lock file has been in place for more than 5 minutes
$time = time() - (int) $timeout;
$left = filemtime($entry) - $time;
// If the amount of time left is less than or equal to 0 unlock the file
if ($left <= 0)
{
unlink($entry);
}
}
else if ($hide_dot == FALSE || ($hide_dot == TRUE && ereg("^\.", $entry) == FALSE))
{
// Determine if the file should be shown, i.e. not .something or file.fileman
$files_array[] = $entry;
}
}
}
// Sort the files and directories
asort($files_array);
asort($subdirs_array);
// Sort the sub directories
foreach($subdirs_array as $entry)
{
if ($entry == "..")
{
if ($dir != $params["root"])
{
// need to check paths like /test/testing/test/
$base = basename($dir);
$prev = ereg_replace("[\\]*$", "", $dir);
$prev = ereg_replace("[/]*$", "", $prev);
$prev = ereg_replace($base . "$", "", $prev);
$prev = eregi_replace($safe, "", $prev);
$prev = ereg_replace("[/]*$", "", $prev);
$prev = ereg_replace("[\\]*$", "", $prev);
$up = "<a href=\"$PHP_SELF?dir=$prev\">..</a>";
}
}
else
{
// Get the UNIX only information
$unix = unix($entry);
$icon = "folder.gif";
// If the folder is locked then show a locked icon
if ($params["htpasswd"] == 1 && eregi("apache", param("SERVER_SOFTWARE", "SERVER")) && file_exists($entry . "/.htaccess") == TRUE && file_exists($entry . "/.htpasswd") == TRUE)
{
$icon = "lockedfolder.gif";
}
// Build the array to parse the template
$subdirs[$entry] = array(
"icon" => "<img src=\"images/icons/$icon\" alt=\"$entry\" title=\"$entry\" />",
"name" => "<a href=\"$PHP_SELF?dir=" . encode_relative($entry) . "\">$entry</a> <a href=\"" . $params["root_url"] . "/" . encode_relative($entry) . "/\" target=\"_blank\">" . "</a>",
"actions" => action_buttons($entry, 1),
"chmod_val" => $unix["chmod"],
"owner" => $unix["owner"],
"group" => $unix["group"],
"mdate" => date($format, filemtime($entry)),
"foldown" => $main["foldown"],
"foldgroup" => $main["foldgroup"],
"chmod" => $main["CHMOD"],
"zipfile" => "<form action=\"#\"><input onclick=\"compress(this, 1);\" type=\"checkbox\" name=\"zipfolder\" value=\"$entry\" title=\"" . $main["checkfolder"] . "\" /></form>"
);
}
}
// Sort the file
foreach($files_array as $entry)
{
// Get the file information
$unix = unix($entry);
$ext = ext($entry);
// Get the file size and increase the counter
$fsize = filesize($entry);
$total = $total + $fsize;
// Get the path to the source file
$sourcefile = encode_relative($entry);
$sourcefile = str_replace("\\", "/", $sourcefile);
$icon = get_icon($entry);
if (file_exists($entry . ".fileman") == TRUE && $edit_lock == 1)
{
$icon = "<img src=\"images/icons/lockedfile.gif\" alt=\"$file\" title=\"$file\" />";
}
$files[$entry] = array(
"icon" => $icon,
"name" => in_array($ext, $ascii) ? "<a href=\"" . $params["root_url"] . "/" . encode_relative($entry) . "\" target=\"_blank\">$entry</a> (<a href=\"javascript:open_window('" . $scripts["source"] . "?f=" . js_safe($sourcefile) . "');\" onmouseover=\"javascript:window.status='" . $main["source"] ."'; return true;\" onmouseout=\"javascript:window.status=''; return true;\">" . $main["source"] . "</a>)" : "<a href=\"" . $params["root_url"] . "/" . encode_relative($entry) . "\" target=\"_blank\">$entry</a>",
"actions" => action_buttons($entry),
"fsize" => size($fsize),
"mdate" => date($format, filemtime($entry)),
"chmod_val" => $unix["chmod"],
"owner" => $unix["owner"],
"group" => $unix["group"],
"fileown" => $main["fileown"],
"filegroup" => $main["filegroup"],
"chmod" => $main["CHMOD"],
"size" => $main["size"],
"zipfile" => "<form action=\"#\"><input onclick=\"compress(this, 0);\" type=\"checkbox\" name=\"zipfile\" value=\"$entry\" title=\"" . $main["checkfile"] . "\" /></form>"
);
}
// Close the active directory
closedir($handle);
I can provide any more info is needed. Please help!!
Thank you to all the PHP build crew out there. 😃