Conversion tables A-K
  Conversion tables L-Z
  SPAM database query
  Reverse WHOIS utility
  North America area codes
  PHP Example forums

PHP example repository.

Web www.web-max.ca
Back to examples
Custom index page with sortable columns.

This is a basic script is the start of a custom index page with sortable columns.

To display the file list, simply enumerate the $file_sort variable to get the key value which you can then use to extract the value from the $file_list variable, for example:

while(list($key, $value)=each($file_sort))
{
    $value = $file_list[$key];
    print($value["name"]);
}

To specify which column you wish to sort, pass the column name in the $sort variable. Specifying 1 in the $r value changes the sort order from ascending to descending.

<?php 
    $this 
$PHP_SELF;

// Set this variable to the directory you are going to browse.
// Remember this is the server path rather than URL.

    
$dir  $DOCUMENT_ROOT;

    
$files opendir($dir);
    
$file_list = array();
    
$file_sort = array();

    if(empty(
$sort))$sort="name";
    if(empty(
$r))    $r=0;

    
$cnt 1;

    while (
$file readdir($files)) 
    {
        
$full_path $dir."/".$file;
        if(!
is_dir($full_path))
        {
            
$ext explode(".",$file);
            
$i=count($ext);
            if(
$i>1)$file_details["ext"] = strtolower($ext[$i-1]);
            
$file_details["name"] = $ext[0];
            
$file_details["size"] = filesize($full_path);
            
$file_details["date"] = filectime($full_path);
            
$file_list[$cnt] = $file_details;

            
$key strtolower($file_details[$sort]);
            
$file_sort[$cnt] = $key;

            
$cnt++;
        }    
    }

    if(
$r)arsort($file_sort);
    else  
asort($file_sort);
?>
 
Example
Downloads

 misc_8.zip