filelist_file.php
Upload User: feiyaoda
Upload Date: 2016-11-21
Package Size: 9556k
Code Size: 14k
Category:

WEB Mail

Development Platform:

PHP

  1. <body  bgcolor='#c3daf9'>
  2. <?php
  3. include ('config.php');
  4. $order_key = $_GET['order_key'];
  5. if (!$order_key) $order_key = $_INI['order_default_key'];
  6. $order_way = $_GET['order_way'];
  7. if (!$order_way) $order_way = $_INI['order_default_way'];
  8. if ($order_way == 'ASC')
  9. {
  10.     $order_icon     = './icones/ASC.png';
  11.     $order_onclick  = 'DESC';
  12. }
  13. else
  14. {
  15.     $order_icon     = './icones/DESC.png';
  16.     $order_onclick  = 'ASC';  
  17. }
  18. // caching
  19. $use_cache_name = 'file-'.md5($_GET['path']).'-'.$order_key.'-'.$order_way.'-'.$_INI['limit_name_length'];
  20. include('pat_cache_begin.php');
  21. /******************************************************************
  22.  *
  23.  *   FILE LISTING SCRIPT
  24.  *
  25.  ******************************************************************/
  26. include ('filelist_common.php');
  27. include ('file_type.php');
  28. include ('./extensions/AudioFile.class.php');
  29. $current_target_type = 'file';
  30. include('filelist_common_header.php');
  31. /******************************************************************
  32.  *
  33.  *   initialising variables
  34.  *
  35.  ******************************************************************/
  36. // icon size : max width and height
  37. $icon_size              = $_INI['icon_size'];
  38. // total size of all files in this folder
  39. $dirsize                = 0;
  40. // arrays corresponding to file and folder for listing
  41. $filelist               = array();
  42. $folderlist             = array();
  43. // total of music in this folder in seconds
  44. $total_of_music_length  = 0;
  45. // this parameter is increased each time a line is rendered. for javascript selection of elements
  46. $element_counter        = 0;
  47. /******************************************************************
  48.  *
  49.  *   Functions
  50.  *
  51.  ******************************************************************/
  52. /*
  53.  *   this function return a human readable information
  54.  *   about a kind of file. it's an array with named keys
  55.  */
  56. function get_file_additionnal_info($info_type,$path)
  57. {
  58.     $ret = array();
  59.     
  60.     switch ($info_type)
  61.     {
  62.         case 'image' :
  63.         {
  64.             // this function doesn't need gd lib to be installed
  65.             list($w,$h) = getimagesize($path);
  66.             $ret['info'] = $w.'w x '.$h.'h';
  67.             break;
  68.         }
  69.         case 'text' :   
  70.         {
  71.             break;
  72.         }  
  73.         case 'sound' :   
  74.         {
  75.             //uses AudioFile.class.php
  76.             $AF = new AudioFile;
  77.             $AF->loadFile($path);
  78.                             
  79.             $alt_str  = 'id : '.$AF->wave_id."n";
  80.             $alt_str .= 'type : '.$AF->wave_type."n";
  81.             $alt_str .= 'compression : '.$AF->wave_compression."n";
  82.             $alt_str .= 'channels : '.$AF->wave_channels."n";
  83.             $alt_str .= 'framerate : '.$AF->wave_framerate."n";
  84.             $alt_str .= 'byterate : '.$AF->wave_byterate."n";
  85.             $alt_str .= 'bits : '.$AF->wave_bits."n";
  86.             $alt_str .= 'length : '.$AF->wave_length."n";
  87.             
  88.             // this is this file length in seconds
  89.             $ret['music_length'] = $AF->wave_length;
  90.         
  91.             if ($AF->id3_tag)
  92.             {
  93.                 $alt_str .= "nID3 Tag :n";
  94.                 $alt_str .= 'title : '.$AF->id3_title."n";
  95.                 $alt_str .= 'artist : '.$AF->id3_artist."n";
  96.                 $alt_str .= 'album : '.$AF->id3_album."n";
  97.                 $alt_str .= 'year : '.$AF->id3_year."n";
  98.                 $alt_str .= 'comment : '.$AF->id3_comment."n";
  99.                 $alt_str .= 'genre : '.$AF->id3_genre."n";
  100.             }
  101.             $ret['info'] = '<acronym title="'.$alt_str.'">Infos</acronym>';
  102.                             
  103.             break;
  104.         }                            
  105.         default:
  106.         {
  107.             //$fileinfo .= "unknownn";
  108.             break;
  109.         }
  110.     }    
  111.     
  112.     return $ret;
  113. }
  114. /*
  115.  *   returns the url to perform action link to affected action
  116.  *
  117.  */
  118. function get_url_for_action($action,$path)
  119. {
  120.     switch ($action)
  121.     {
  122.         case 'php_highlight' : 
  123.         {
  124.             $actionurl  = 'view_source.php?hltype=php&path='.$path; 
  125.             $target = '_blank';
  126.             break;
  127.         }
  128.         case 'xml_highlight' : 
  129.         {
  130.             $actionurl  = 'view_source.php?hltype=xml&path='.$path; 
  131.             $target = '_blank';
  132.             break;
  133.         }        
  134.         case 'view' :
  135.         {
  136.             $actionurl  = $path;
  137.             $target = '_blank';
  138.             break;
  139.         }
  140.         default:
  141.         {
  142.             $actionurl  = 'pat_default_action.php?target_file='.$path; 
  143.             break;
  144.         }
  145.     }
  146.     return array($actionurl,$target);
  147. }
  148. /******************************************************************
  149.  *
  150.  *   Rendering html header and javascript
  151.  *
  152.  ******************************************************************/
  153. if (FALSE == is_dir($_GET['path']))
  154. {
  155.     echo "<body bgcolor='#CFE3E3'><p class="error_box">ERROR, there is no folder at that place. url : ".$_SERVER["REQUEST_URI"]."n";
  156.     exit;
  157. }
  158. $dp = opendir($_GET['path']);
  159. if (FALSE == $dp)
  160. {
  161.     echo "<body bgcolor='#CFE3E3'><p class="error_box">ERROR, impossible to reach this folder. check php user permission on it</p>n";
  162.     exit;
  163. }
  164. /******************************************************************
  165.  *
  166.  *  We read entire folder and set for each element all values
  167.  *  needed to render or to sort it
  168.  *
  169.  ******************************************************************/
  170.  
  171. while (false !== ($file = readdir($dp)))
  172. {
  173.     if ('.' == $file) continue;
  174.     if ('..' == $file) continue;
  175.     
  176.     // ALL THIS PARAMETERS WILL BE SET IN $filelist or $folderlist arrays WITH THE SAME NAME
  177.     
  178.     // relative path to object for use in php functions
  179.     $path           = $_GET['path'].$file;
  180.     
  181.     // this parameter is used in form to store in independent *slashes() functions
  182.     // path to current file
  183.     $url            = urlencode($url);
  184.     
  185.     // last modification time
  186.     $file_mod_time  = filemtime($path);
  187.     
  188.     // permissions
  189.     $file_perms     = fileperms($_GET['path'].$file);
  190.     
  191.     // size
  192.     $filesize       = '';
  193.     
  194.     // extension of file if it's one. used in filetype.php to know what to do with
  195.     // this kind of file
  196.     $ext            = '';
  197.     
  198.     // icon related to this kind of file
  199.     $icon           = '';
  200.     
  201.     // what to display when mouse is over icon
  202.     $icon_alt       = '';
  203.     
  204.     // type is the one get from filetype.php
  205.     $type           = '';
  206.     
  207.     // name is what will be displayed on screen for this file
  208.     $name           = '';
  209.     
  210.     // on click : what to do?
  211.     $actionurl      = '';
  212.     
  213.     // on click : where to?
  214.     $target         = '';
  215.     
  216.     // additionnal informations about file (try on a sound file like a mp3 ;)
  217.     $fileinfo       = '';    
  218.         
  219.     if (is_dir($_GET['path'].$file))
  220.     {
  221.         $icon       = $_INT['theme_path'].'icones/folder.png';
  222.         $type       = 'Dossier';
  223.         $name       = $file;
  224.         $actionurl  = 'filelist_file.php?path='.$_GET['path'].$file.'/';
  225.         
  226.         $folderlist[$path]['path']            = $path;
  227.         $folderlist[$path]['url']             = $url;
  228.         $folderlist[$path]['file_mod_time']   = $file_mod_time;
  229.         $folderlist[$path]['file_perms']      = $file_perms;
  230.         $folderlist[$path]['filesize']        = $filesize;
  231.         $folderlist[$path]['ext']             = $ext;
  232.         $folderlist[$path]['icon']            = $icon;
  233.         $folderlist[$path]['icon_alt']        = $icon_alt;
  234.         $folderlist[$path]['type']            = $type;
  235.         $folderlist[$path]['name']            = $name;
  236.         $folderlist[$path]['actionurl']       = $actionurl;
  237.         $folderlist[$path]['fileinfo']        = $fileinfo;        
  238.     }
  239.     else
  240.     {
  241.         // file size
  242.         $filesize   = filesize($path);
  243.         
  244.         // adding size of this file to total folder size
  245.         $dirsize   += $filesize;
  246.         
  247.         // getting extensions
  248.         $parts = explode('.',$file);
  249.         $ext = strtolower($parts[(count($parts)-1)]);  
  250.         
  251.         // NAME parameter
  252.         // get the filename with or without extension and replaces under score with spaces
  253.         if (FALSE != $_INI['leave_name_extension'])
  254.         {
  255.             $name = $file;
  256.         }
  257.         else
  258.         {
  259.             unset($parts[(count($parts)-1)]);
  260.             $name = implode(' ',$parts);
  261.             $name = str_replace('_',' ',$name);
  262.         }        
  263.         // getting settings for this kind of file (in filetype.php)
  264.         if (is_array($file_type[$ext]))
  265.         {
  266.             $type   = $file_type[$ext]['name'];
  267.             $icon   = $_INT['theme_path'].'icones/'.$file_type[$ext]['icon'];
  268.             $action = $file_type[$ext]['action'];
  269.             $info_type = $file_type[$ext]['type'];
  270.             
  271.             list($actionurl,$target) = get_url_for_action($action,$path);
  272.         }
  273.         else
  274.         {
  275.             // default action when we got nothing
  276.             $actionurl  = './pat_default_action.php?target_file='.$_GET['path'].$file;
  277.             $type       = '';
  278.             $icon       = '';
  279.             $action     = '';
  280.         }
  281.             
  282.         // over-ridding with default values if needed 
  283.         if ('' == $type)
  284.             $type   = $ext.' Fichier';
  285.             
  286.         if (!is_file($icon))
  287.         {
  288.             $icon   = $_INT['theme_path'].'icones/unknown.png';          
  289.         }
  290.         // for each type of file if a specific information is usable then we draw it
  291.         if ($_INI['show_fileinfo'])
  292.              $file_infos = get_file_additionnal_info($info_type,$_GET['path'].$file);
  293.         
  294.         $fileinfo = $file_infos['info'];
  295.         if ($file_infos['music_length']) $total_of_music_length += $file_infos['music_length'];
  296.         
  297.         $filelist[$path]['path']            = $path;
  298.         $filelist[$path]['url']             = $url;
  299.         $filelist[$path]['file_mod_time']   = $file_mod_time;
  300.         $filelist[$path]['file_perms']      = $file_perms;
  301.         $filelist[$path]['filesize']        = $filesize;
  302.         $filelist[$path]['ext']             = $ext;
  303.         $filelist[$path]['icon']            = $icon;
  304.         $filelist[$path]['icon_alt']        = $icon_alt;
  305.         $filelist[$path]['type']            = $type;
  306.         $filelist[$path]['name']            = $name;
  307.         $filelist[$path]['actionurl']       = $actionurl;
  308.         $filelist[$path]['target']          = $target;
  309.         $filelist[$path]['fileinfo']        = $fileinfo;
  310.     }
  311.     
  312. }
  313. closedir($dp);
  314. /******************************************************************
  315.  *
  316.  *   Rendering html body
  317.  *
  318.  ******************************************************************/
  319. echo "<form name="data_container_element_table">n";
  320. echo "<table cellpadding=2 cellspacing=0>n";
  321. echo "<tr>n";
  322. // rerender
  323. foreach ($_GET as $key => $val) $get_line .= $key.'='.$val.'&';
  324. $get_line .= 'cache-re-render=1';
  325. $rerender = "<a href="".basename($_SERVER["SCRIPT_FILENAME"])."?$get_line"><img src="".$_INT['theme_path']."icones/refresh.png" width=16 height=16 border=0></a>n";
  326.         
  327. //$order_icon$order_onclick
  328. $classes['name'] = 'colomn_header';
  329. $classes['type'] = 'colomn_header';
  330. $classes['filesize'] = 'colomn_header';
  331. $classes['mod'] = 'colomn_header';
  332. $classes[$order_key] = 'colomn_header_ordered';
  333. $order_link  = "<a href="filelist_file.php?order_way=$order_onclick&order_key=name&path=".$_GET['path']."">n";
  334. $order_link .= "<img src="".$_INT['theme_path']."$order_icon" border="O"></a>n";
  335. echo "  <th class="".$classes['name']."" align="left" colspan=2>$rerender$order_link Nom</th>n";
  336. // size
  337. if ($_INI['show_size'])
  338. {
  339.     $order_link = "<a href="filelist_file.php?order_way=$order_onclick&order_key=filesize&path=".$_GET['path'].""><img src="".$_INT['theme_path']."$order_icon" border="O"></a>n";
  340.     echo "  <th class="".$classes['filesize']."" align="right">$order_link Taille</th>n";
  341. }
  342. //type
  343. if ($_INI['show_filetype'])
  344. {
  345.     $order_link = "<a href="filelist_file.php?order_way=$order_onclick&order_key=type&path=".$_GET['path'].""><img src="".$_INT['theme_path']."$order_icon" border="O"></a>n";
  346.     echo "  <th class="".$classes['type']."">$order_link Type</th>n";
  347. }
  348. // file additionnal informations
  349. if ($_INI['show_fileinfo'])
  350. {
  351.     echo "  <th class="colomn_header">Informations</th>n";
  352. }
  353. // lastmod
  354. if ($_INI['show_lastmod'])
  355. {
  356.     $order_link = "<a href="filelist_file.php?order_way=$order_onclick&order_key=mod&path=".$_GET['path'].""><img src="".$_INT['theme_path']."$order_icon" border="O"></a>n";
  357.     echo "  <th class="".$classes['mod']."">$order_link Derni鑢e Modification</th>n";
  358. }
  359. // file rights
  360. if ($_INI['show_rights'])
  361.     echo "  <th class="colomn_header">Rights</th>n";
  362. echo "</tr>n";
  363. // 1. merging
  364. if($_INI['mix_files_and_folders'])
  365. {
  366.     $full_list = array_merge($folderlist,$filelist);
  367.     
  368.     if (is_array($full_list))
  369.     {    
  370.         $array_to_render = adv_sort($full_list);
  371.         render_list($array_to_render);
  372.     }
  373. }
  374. else
  375. {
  376.     if (is_array($folderlist))
  377.     {
  378.         $array_to_render = adv_sort($folderlist);
  379.         render_list($array_to_render);    
  380.     }
  381.     if (is_array($filelist))
  382.     {
  383.         $array_to_render = adv_sort($filelist);
  384.         render_list($array_to_render);
  385.     }
  386. }
  387. echo "</table>n";
  388. /******************************************************************
  389.  *
  390.  *   Rendering html footer
  391.  *
  392.  ******************************************************************/
  393. echo "<hr>n";
  394. echo "<body  bgcolor='#E1E4FA'><table border=0>n";
  395. echo "  <tr><th>Chemin</th><td>".realpath_alternative($_GET['path'],true)."</td></tr>n";
  396. echo "  <tr><th>Dossiers</th><td>".count($folderlist)."</td></tr>n";
  397. echo "  <tr><th>fichiers</th><td>".count($filelist)."</td></tr>n";
  398. echo "  <tr><th>Taille total</th><td>".FormatTailleFichier($dirsize,'octets')."</td></tr>n";
  399. if ($total_of_music_length)
  400.     echo "<tr><th>Total music time</th><td>".timetohms($total_of_music_length)."</b> ($total_of_music_length)</td>n";
  401. echo "</table>n";
  402. echo "<input type="hidden" name="total_elements" value="".$element_counter."">n";
  403. echo "</form>n";  
  404. /******************************************************************
  405.  *
  406.  *   storing in cache
  407.  *
  408.  ******************************************************************/
  409. include('pat_cache_store.php');