ayand04

list

Jun 10th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1. <?php
  2.  $thelist = '';
  3.  $count = 0;
  4.  $filelist = array();
  5.  if ($handle = opendir('./storage')) {
  6.    while (false !== ($file = readdir($handle))) {
  7.           if ($file != "." && $file != "..") {
  8.               $filelist[] = $file;
  9.               $count = $count+1;
  10.           }
  11.        }
  12.        closedir($handle);
  13. }
  14. /*var_dump($filelist);*/
  15. function human_filesize($bytes, $decimals = 2) {
  16.     $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
  17.     $factor = floor((strlen($bytes) - 1) / 3);
  18.     return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
  19. }
  20.  
  21. function findexts ($filename) {
  22.     $filename=strtolower($filename);
  23.     $exts= pathinfo($filename, PATHINFO_EXTENSION);
  24.     return $exts;
  25. }
  26.  
  27. for($index=0; $index<$count; $index++){
  28.     $name = pathinfo($filelist[$index], PATHINFO_FILENAME);
  29.     $namehref = $filelist[$index];
  30.     $extn = findexts($filelist[$index]);
  31.     $size = human_filesize(filesize('./storage/'.$filelist[$index]));
  32.     $thelist .= '<li><span class="type">'.$extn.'</span><span class="link"><a href=./storage/'.$namehref.'>'.$name.'</a></span><span class="size">'.$size.'</span><span class="fa fa-trash-o fa-fw" aria-hidden="true"></span>
  33. </li>';
  34. }
  35.  
  36. if($count > 0){
  37.     echo json_encode(array('heading' => '<div id="found">Here is all!</div>', 'list' => $thelist));
  38. }
  39. else{
  40.     echo json_encode(array('heading' => '<div id="empty_storage"><img src="icon.png"><br>Its lonely here!</div>', 'list' => $thelist));
  41. }
  42. ?>
Add Comment
Please, Sign In to add comment