Forum Moderators: coopster
my code as following:
// to list all the folder and file in the directory
function scanfile($dirName,$doRecursive) {
$d = dir($dirName);
$lastModified = 0;
$directory = array();
$row = 0;
while($entry = $d->read()) {
if ($entry!= "." && $entry!= ".."){
if (!is_dir($dirName."/".$entry) ) {
$directory[$row]['name'] = $entry;
$directory[$row]['link'] = $dirName."/".$entry;
$directory[$row]['last modified date'] = date("d.m.Y h:i",filemtime($dirName."/".$entry));
$directory[$row]['size'] = formatfilesize(get_size($dirName."/".$entry));
$row = $row +1;
}else if ($doRecursive && is_dir($dirName."/".$entry)) {
}else{
$directory[$row]['name'] = $entry;
$directory[$row]['link'] = $dirName."/".$entry;
$directory[$row]['last modified date'] = date("d.m.Y h:i",filemtime($dirName."/".$entry));
$directory[$row]['size'] = formatfilesize(get_size($dirName."/".$entry));
$row = $row +1;
}
}
}
$d->close();
return $directory;
}
$tittle_array = array();
$array = scanfile($path,0);
print_r($array);
$arrayRow = sizeof($array);
for($row = 0; $row<$arrayRow; $row++){
$tittle_array[$row] = $array[$row]['name'];
}
// This will sort on value
//$soft ="sort=1";
if($_GET['sort'] == '1'){
//array_ukmultisort($array, "cmp");
$sorted = BubbleSort($tittle_array,1);
$soft ="sort=0";
}else{
$sorted = BubbleSort($tittle_array,0);
$soft ="sort=1";
}
i need to sort the all file and folder in the directory when i click on the following header:
---------------------------
Name ¦Last modified ¦ size¦
---------------------------
a.file 10/08/2006 10KB
<th colspan="2" class="thH"> <a href="?<?php echo $soft?>" >Name</a></th>
pls help me, i dont know how to solve it.
thx
where is the code for the actual sorting? I see a couple of user defined functions there but no code.
BubbleSort being one
you might have a typo here
array_ukmultisort
is that user defined or should it be array_multisort? (yes I realize it's commented but I was wondering if that may be part of why some attempts didn't work)
I assume you are trying to sort a multidimensional array like this
$directory[$row]['name'] = $entry;
$directory[$row]['link'] = $dirName."/".$entry;
$directory[$row]['last modified date'] = date("d.m.Y h:i",filemtime($dirName."/".$entry));
$directory[$row]['size'] = formatfilesize(get_size($dirName."/".$entry));
array_multisort [php.net] should work
function scanfile($dirName,$doRecursive) {
$d = dir($dirName);
$lastModified = 0;
$directory = array();
$row = 0;
while($entry = $d->read()) {
if ($entry!= "." && $entry!= ".."){
if (!is_dir($dirName."/".$entry) ) {
$directory[$row]['name'] = $entry;
$directory[$row]['link'] = $dirName."/".$entry;
$directory[$row]['last modified date'] = date("d.m.Y h:i",filemtime($dirName."/".$entry));
$directory[$row]['size'] = formatfilesize(get_size($dirName."/".$entry));
$row = $row +1;
}else if ($doRecursive && is_dir($dirName."/".$entry)) {
}else{
$directory[$row]['name'] = $entry;
$directory[$row]['link'] = $dirName."/".$entry;
$directory[$row]['last modified date'] = date("d.m.Y h:i",filemtime($dirName."/".$entry));
$directory[$row]['size'] = formatfilesize(get_size($dirName."/".$entry));
$row = $row +1;
}
}
}
$d->close();
//sort the value
if($_GET['sort'] == '1'){
rsort($directory);
//array_multisort("name", SORT_DESC, SORT_STRING,"last modified date", SORT_NUMERIC, SORT_DESC,
$directory );
print_r($directory);
}else{
sort($directory);
//array_multisort("name", SORT_ASC, SORT_STRING,"last modified date", SORT_NUMERIC, SORT_ASC,
$directory );
print_r($directory);
}
return $directory;
}
$tittle_array = array();
$array = scanfile($path,0);
// This will sort on value
$soft ="sort=1";
if($_GET['sort'] == '1'){
$soft ="sort=0";
scanfile($path,0);
}else{
$soft ="sort=1";
scanfile($path,0);
}
<th colspan="2" class="thH"> <a href="?<?php echo $soft;?>">Name</a></th>
the code seem work on 1st record only but when i use array_multisort, the program cannot sort anymore. i dont know wat happen..
pls give my some opinion.