Ready to use sortable directory listing (PHP)

 
Post new topic   Reply to topic    Aprelium Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
Vesku
-


Joined: 13 Nov 2006
Posts: 11

PostPosted: Thu Jul 19, 2007 4:28 pm    Post subject: Ready to use sortable directory listing (PHP) Reply with quote

Here is a sortable Abyss-look-a-like Directory Listing made with php.
Works also with virtual directories.

To install:

Copy the code and save it as a .php -file to your server folder.
Go to Abyss console > Confugure > Directory Listing > From Script >
Browse and point out the file. Press OK and Restart.

All the best,
Vesku

Code:

<?php

// *********************************************************************
// *  Sortable Directory Listing script for Abyss Web Server           *
// *  Lists Directories first.                                         *
// *  by Vesku 29/7/2007                                               *
// *  Works also with virtual directories.                             *
// *                                                                   *
// *********************************************************************
error_reporting(0);

function sizeformat($size)
{
   if($size<1024)
    {
        return $size." bytes";
    }
    else if($size<(1024*1024))
    {
        $size=round($size/1024,1);
        return $size." KB";
    }
    else if($size<(1024*1024*1024))
    {
        $size=round($size/(1024*1024),1);
        return $size." MB";
    }
    else
    {
        $size=round($size/(1024*1024*1024),1);
        return $size." GB";
    }
}


function dateformat($date)
{
    $separate = split('[- :]', $date);
    $year = $separate[0];
    $month = $separate[1];
    $day = $separate[2];
    $hour = $separate[3]+3; //+timezone
    $minute = $separate[4];
    $second = $separate[5];
    $date = mktime($hour,$minute,$second,$month,$day,$year);
    $date = date("d.m.Y H:i", $date);
    return $date;
}

// Reading Abyss dirlist

  $lines = explode("\n", $_POST['files']);
  for ($i=0; $i < count($lines); $i++)  {

      $array = explode("\t", $lines[$i]);
         if ($array[1] == "../") {
            $dotdot = '1';
            $dotdotdate = $array[3];}

      $id[] = $i;
      $name[] = $array[0];
      $url[] = $array[1];
      $size[] = $array[2];
      $date[] = $array[3];
      $type[] = $array[4];

      if ($type[$i] == "") {$type[$i] = "Directory";}
  }

   $dir = array($name, $url, $size, $date, $type, $id);



// Sorting section

   $nameth = 'S=N&amp;O=A';
   $sizeth = 'S=S&amp;O=A';
   $dateth = 'S=D&amp;O=A';
   $mimeth = 'S=T&amp;O=A';

   switch ($_GET['S']) {
      case 'N':
         switch ($_GET['O']) {
            case 'A':
               array_multisort($dir[5], SORT_REGULAR, SORT_ASC, $dir[1], $dir[0], $dir[4], $dir[3], $dir[2]);
               $nameth = "S=N&amp;O=D";
               break;
            case 'D':
               array_multisort($dir[5], SORT_REGULAR, SORT_DESC, $dir[1], $dir[0], $dir[4], $dir[3], $dir[2]);
               break;
         }
         break;
      case 'S':
         switch ($_GET['O']) {
            case 'A':
               array_multisort($dir[2], SORT_NUMERIC, SORT_ASC, $dir[5], $dir[1], $dir[0], $dir[4], $dir[3]);
               $sizeth = "S=S&amp;O=D";
               break;
            case 'D':
               array_multisort($dir[2], SORT_NUMERIC, SORT_DESC, $dir[5], $dir[1], $dir[0], $dir[4], $dir[3]);
               break;
         }
         break;
      case 'D':
         switch ($_GET['O']) {
            case 'A':
               array_multisort($dir[3], SORT_REGULAR, SORT_ASC, $dir[5], $dir[1], $dir[0], $dir[4], $dir[2]);
               $dateth = "S=D&amp;O=D";
               break;
            case 'D':
               array_multisort($dir[3], SORT_REGULAR, SORT_DESC, $dir[5], $dir[1], $dir[0], $dir[4], $dir[2]);
               break;
         }
         break;
      case 'T':
         switch ($_GET['O']) {
            case 'A':
               array_multisort($dir[4], SORT_REGULAR, SORT_ASC, $dir[5], $dir[1], $dir[0], $dir[3], $dir[2]);
               $mimeth = "S=T&amp;O=D";
               break;
            case 'D':
               array_multisort($dir[4], SORT_REGULAR, SORT_DESC, $dir[5], $dir[1], $dir[0], $dir[3], $dir[2]);
               break;
         }
         break;
      default:
         $nameth = 'S=N&amp;O=D';
         break;
   }

// HTML section

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>
<TITLE>Index of <?php echo rawurldecode($_POST['path']); ?></TITLE>
<style type="text/css">
TABLE {font-family: monospace;
font-size: smaller;}
TD {padding-right: 1em;}
</style>
</HEAD>
<BODY><H2>Index of <?php echo rawurldecode($_POST['path']); ?></H2>
<HR>
<TABLE BORDER="0">
<?php
echo "<TR><TH><a href=\"?$nameth\">Name</a></TH><TH><a href=\"?$sizeth\">Size</a></TH><TH><a href=\"?$dateth\">Date</a></TH><TH><a href=\"?$mimeth\">MIME Type</a></TH></TR>";

/*
echo "<PRE>";
print_r($dir);
echo "</PRE>";
*/


// Printing dotdotdir

   if ($dotdot == "1") {
   echo '<TR><TD><A HREF="../">[Parent Directory]</A></TD><TD NOWRAP ALIGN="RIGHT">&lt;DIR&gt;</TD><TD NOWRAP>';
   echo dateformat($dotdotdate).'</TD><TD NOWRAP>Directory</TD></TR>'."\n";
   }


// Printing Directories


   for($i=0;$i<count($lines);$i++) {

      if ($dir[1][$i] != "../") {
        if ($dir[4][$i] == "Directory") {
         echo '<TR><TD><A HREF="'.$dir[1][$i].'">['.str_replace('/', '', $dir[0][$i]).']</A></TD><TD NOWRAP ALIGN="RIGHT">';
         echo "&lt;DIR&gt;";
         echo '</TD><TD NOWRAP>'.dateformat($dir[3][$i]).'</TD><TD NOWRAP>';
         echo $dir[4][$i];
         echo '</TD></TR>'."\n";
        }
      }
   }


// Printing Files


   for($i=0;$i<count($lines);$i++) {

      if ($dir[4][$i] != "Directory") {
         echo '<TR><TD><A HREF="'.$dir[1][$i].'">'.$dir[0][$i].'</A></TD><TD NOWRAP ALIGN="RIGHT">';
         echo sizeformat($dir[2][$i]);
         echo '</TD><TD NOWRAP>'.dateformat($dir[3][$i]).'</TD><TD NOWRAP>';
         echo $dir[4][$i];
         echo '</TD></TR>'."\n";
      }
   }

?>
</TABLE>
<br><HR>
Powered by <b><i>Abyss Web Server</i></b> X1<br>&copy; <a href="http://www.aprelium.com">Aprelium Technologies</a> - 2001-2007
</BODY>
</HTML>


Last edited by Vesku on Mon Jul 30, 2007 7:55 pm; edited 4 times in total
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Jul 19, 2007 11:04 pm    Post subject: Reply with quote

Vesku,

Thank you for the script. By the way, we've moved it to the Tutorials section to give it more exposure.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
badai
-


Joined: 24 Apr 2003
Posts: 82

PostPosted: Sun Jul 29, 2007 4:41 pm    Post subject: Reply with quote

first time i try to list, it just hang and i have to reload.

it always sort by name and cannot sort by size, date or mime type.

something wrong?
Back to top View user's profile Send private message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Sun Jul 29, 2007 7:07 pm    Post subject: Reply with quote

badai wrote:
first time i try to list, it just hang and i have to reload.

it always sort by name and cannot sort by size, date or mime type.

something wrong?


Vesku, wrote the PHP script to use Register Globals. This is bad practice in PHP programming and can lead to problems in the future. PHP6 will no longer use Register Gobals, so it's a good idea to always use the $_ type variables. $_SERVER, $_GET, $_POST etc.
Back to top View user's profile Send private message Visit poster's website
Vesku
-


Joined: 13 Nov 2006
Posts: 11

PostPosted: Sun Jul 29, 2007 11:04 pm    Post subject: Reply with quote

Sorry about that. I did not test it with register_globals off.
:oops:

I made corrections to script. Now it should work also with register_globals = Off (in php.ini).

Br. Vesku
Back to top View user's profile Send private message
badai
-


Joined: 24 Apr 2003
Posts: 82

PostPosted: Mon Jul 30, 2007 7:29 am    Post subject: Reply with quote

Notice: Undefined offset: 5 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 6 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 7 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 8 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 9 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 10 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 11 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 12 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 13 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 14 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 15 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 16 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 17 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 18 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 19 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 20 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 21 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 22 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 23 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 24 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 25 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 26 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 27 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 28 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 29 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 30 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

Notice: Undefined offset: 31 in C:\Program Files\Abyss Web Server\htdocs\test.php on line 55

then it will list everything, still can only sort in name.
Back to top View user's profile Send private message
Vesku
-


Joined: 13 Nov 2006
Posts: 11

PostPosted: Mon Jul 30, 2007 7:56 pm    Post subject: Reply with quote

Maybe now it finally works ??
Back to top View user's profile Send private message
badai
-


Joined: 24 Apr 2003
Posts: 82

PostPosted: Tue Jul 31, 2007 2:49 am    Post subject: Reply with quote

seem like it's working. thank you.
Back to top View user's profile Send private message
badai
-


Joined: 24 Apr 2003
Posts: 82

PostPosted: Sat Nov 17, 2007 8:36 am    Post subject: Reply with quote

the date/time is not local date/time. i think it's GMT

how do i get it to display local date/time?

i think this is the function

Code:
function dateformat($date)
{
    $separate = split('[- :]', $date);
    $year = $separate[0];
    $month = $separate[1];
    $day = $separate[2];
    $hour = $separate[3]+3; //+timezone
    $minute = $separate[4];
    $second = $separate[5];
    $date = mktime($hour,$minute,$second,$month,$day,$year);
    $date = date("d.m.Y H:i", $date);
    return $date;
}
Back to top View user's profile Send private message
Vesku
-


Joined: 13 Nov 2006
Posts: 11

PostPosted: Sat Nov 17, 2007 9:33 am    Post subject: Reply with quote

badai wrote:
the date/time is not local date/time. i think it's GMT

how do i get it to display local date/time?



Hello -
Yes, you can change timezone (in my code set to +3) to example -7.
You can also change date/time display format by changing "d.m.Y H:i" to any format you wish. Please check http://www.php.net/date/ for details.

Br. Vesku
Back to top View user's profile Send private message
badai
-


Joined: 24 Apr 2003
Posts: 82

PostPosted: Sat Nov 17, 2007 9:59 am    Post subject: Reply with quote

thank you
Back to top View user's profile Send private message
Vesku
-


Joined: 13 Nov 2006
Posts: 11

PostPosted: Mon Jan 07, 2008 8:18 pm    Post subject: Reply with quote

Hi -
I made some improvements to this script.

- CSS style
- Icons
- Force Download
- cut long filenames
- etc...

Can someone test this in linux/mac because i only have windows machines, please. ?? I want to know if force download works ok with all systems. Specially with virtual paths.


I am NOT a professional, so use this forcedownload -feature with your own risk. Anyway, it should be safe :\

Script can be downloaded here:

Download


edit: link corrected


Last edited by Vesku on Mon Oct 26, 2009 10:52 am; edited 2 times in total
Back to top View user's profile Send private message
badai
-


Joined: 24 Apr 2003
Posts: 82

PostPosted: Tue Jan 08, 2008 3:22 pm    Post subject: Reply with quote

thank you.
Back to top View user's profile Send private message
Vesku
-


Joined: 13 Nov 2006
Posts: 11

PostPosted: Tue Jan 08, 2008 7:17 pm    Post subject: Reply with quote

Minor changes made. Make sure you have the latest version.
Back to top View user's profile Send private message
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Wed Jan 09, 2008 9:31 pm    Post subject: Reply with quote

Vesku wrote:
Minor changes made. Make sure you have the latest version.


We will give it a try on Mac and Linux and let you know if it needs some changes.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Vahn
-


Joined: 10 Aug 2005
Posts: 51
Location: At my computer

PostPosted: Sun Jan 27, 2008 9:11 pm    Post subject: Reply with quote

hey,

This its pretty neat, i did some playing arround and i got some nice results, thanks to you.

http://i164.photobucket.com/albums/u13/VahnNoa/scriptvahn.png?t=1201464652

[edit]
I just put the newest version of your script on my Kubuntu (Debian linux) box and tried it out, no luck but i think the error ( no Input File Specified. ) may be something i broke with abyss?

Gonna keep pokeing at it...
[/edit]

Reguards
-Vahn
_________________
A ship in the harbor is safe, But thats not what Ships were Built for. ~ John Shedd
Success Comes before Work only in the Dictionary ~ Harvey Mackay
Back to top View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Jan 31, 2008 5:22 pm    Post subject: Reply with quote

Vahn wrote:
hey,

This its pretty neat, i did some playing arround and i got some nice results, thanks to you.

http://i164.photobucket.com/albums/u13/VahnNoa/scriptvahn.png?t=1201464652


Very nice looking listing!!
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Tutorials All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group