r4m0n

Emperror Upload Bin

Jan 30th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.63 KB | None | 0 0
  1. <?php
  2. $serverpath = dirname($_SERVER['SCRIPT_FILENAME']).'/';
  3. $serverpath_url = '';
  4. $max = 1024*1024*1024;
  5. $passwd = 'yourpasshere';
  6.  
  7. function ShowSize ($filesize) {
  8.     if ($filesize < 1024) {
  9.         echo $filesize."B";
  10.     } elseif ($filesize < pow(1024,2)) {
  11.         echo number_format($filesize/1024, 2)."KB";
  12.     } elseif ($filesize < pow(1024,3)) {
  13.         echo number_format($filesize/pow(1024,2),2)."MB";
  14.     } else {
  15.         echo number_format($filesize/pow(1024,3),2)."GB";
  16.     }
  17. }
  18.  
  19. session_start();
  20.  
  21. if (isset($_REQUEST['passwd'])) {
  22.     if ($_REQUEST['passwd'] == $passwd) {
  23.         $_SESSION['logado'] = true;
  24.     }
  25. }
  26.  
  27. if (empty($_SESSION['logado'])) {
  28. ?>
  29. <html>
  30. <head><title>Emperror Upload Bin</title></head>
  31. <body>
  32. <form action="index.php" method="POST">
  33. Password: <input name="passwd" type="password">
  34. <input type="submit" value="Send">
  35. </form>
  36. </body>
  37. </html>
  38. <?php } else { ?>
  39. <html>
  40. <head><title>Emperror Upload Bin</title></head>
  41. <body>
  42. <?php
  43. if (isset($_REQUEST['kill'])) {
  44.     if ($_REQUEST['kill'] == basename($_SERVER['SCRIPT_FILENAME'])) { ?>
  45.         Invalid file!<br>
  46. <?php   } elseif (unlink($serverpath.$_REQUEST['kill'])) { ?>
  47.         File deleted!<br>
  48. <?php   } else { ?>
  49.         Error deleting file!<br>
  50. <?php   }
  51. }
  52. if (isset($_REQUEST['killfiles'])) {
  53.     foreach ($_REQUEST['killfiles'] as $file) {
  54.         if ($file == basename($_SERVER['SCRIPT_FILENAME'])) { ?>
  55.             Invalid file!<br>
  56.     <?php   } elseif (unlink($serverpath.$file)) { ?>
  57.             File deleted!(<?php echo $file; ?>)<br>
  58.     <?php   } else { ?>
  59.         Error deleting file!(<?php echo $file; ?>)<br>
  60.     <?php   }
  61.     }
  62. }
  63. if (isset($_REQUEST['url'])) {
  64.     $urls = explode("\r\n", $_REQUEST['url']);
  65.     if (count($urls) == 1) $urls = explode("\n", $_REQUEST['url']);
  66.     foreach ($urls as $u) {
  67.         $p = explode(' ', $u);
  68.         if (count($p) == 2) {
  69.             $bn = basename($p[1]);
  70.             $u = $p[0];
  71.         } else {
  72.             $bn = basename($p[0]);
  73.             $u = $p[0];
  74.         }
  75.         if ($bn == basename($_SERVER['SCRIPT_FILENAME'])) { ?>
  76.             Invalid file name!<br>
  77.         <?php
  78.         } else {
  79.             $f = fopen($serverpath.$bn, 'w');
  80.             $c = curl_init($u);
  81.             curl_setopt($c, CURLOPT_HEADER, false);
  82.             curl_setopt($c, CURLOPT_FILE, $f);
  83.             if (curl_exec($c)) {
  84.                 chmod($serverpath.$bn,0664); ?>
  85.                 File transfered! (<?php echo $u; ?> -> <?php echo $bn; ?>)<br>
  86.         <?php   } else { ?>
  87.                 Error transfering file! (<?php echo $u; ?>)<br>
  88.         <?php   }
  89.             curl_close($c);
  90.             fclose($f);
  91.         }
  92.     }
  93. }
  94. if (isset($_FILES['upfile'])) {
  95.     if ($_FILES['upfile']['name'] == basename($_SERVER['SCRIPT_FILENAME'])) { ?>
  96.         Invalid file!<br>
  97. <?php   } elseif (move_uploaded_file($_FILES['upfile']['tmp_name'], $serverpath.$_FILES['upfile']['name'])) {
  98.         chmod($serverpath.$_FILES['upfile']['name'],0664); ?>
  99.         File sent!<br>
  100. <?php   } else { ?>
  101.         Error sending file!<br>
  102. <?php   }
  103. } ?>
  104. Uploaded files:
  105. <table width="100%" border="1">
  106.   <tr>
  107.     <td>Sel</td>
  108.     <td>Name</td>
  109.     <td width="20%">Size</td>
  110.     <td width="20%">Date/Time</td>
  111.     <td width="10%">&nbsp;</td>
  112.   </tr>
  113. <form action="index.php" method="post">
  114. <?php
  115. $dir = opendir($serverpath);
  116. $f_total = 0;
  117.  
  118. $files = array();
  119. while (false !== ($file = readdir($dir))) {
  120.     $files[] = $file;
  121. }
  122. sort($files);
  123.  
  124. foreach ($files as $file) if (($file != ".") and ($file != "..") and ($file != basename($_SERVER['SCRIPT_FILENAME']))) { ?>
  125. <tr>
  126.     <td><input type="checkbox" name="killfiles[]" value="<?php echo $file; ?>"></td>
  127.     <td><a href="<?php echo $serverpath_url.$file; ?>"><?php echo $file; ?></a></td>
  128.     <td align="right"><?php echo ShowSize(filesize($serverpath.$file)); ?>&nbsp;&nbsp;&nbsp;&nbsp;</td>
  129. <?php $f_total += (filesize($serverpath.$file)); ?>
  130.     <td align="right"><?php echo date ("Y-m-d H:i:s", filemtime($serverpath.$file)); ?>&nbsp;&nbsp;&nbsp;&nbsp;</td>
  131.     <td align="right"><a href="<?php echo basename($_SERVER['SCRIPT_FILENAME']); ?>?kill=<?php echo $file; ?>">Delete</a>&nbsp;&nbsp;
  132. </tr>
  133. <?php
  134. }
  135. ?>
  136. <tr>
  137.     <td><br>Disk space used:</td>
  138.     <td align="right"><?php echo ShowSize($f_total); ?>&nbsp;&nbsp;&nbsp;&nbsp;</td>
  139.     <td colspan="3">&nbsp;</td>
  140. </tr>
  141. <tr>
  142.     <td colspan="5"><input type="submit" value="Delete Selected"></td>
  143. </tr>
  144. </form>
  145. </table>
  146. <?php if ($f_total <= $max) { ?>
  147. <form enctype="multipart/form-data" action="index.php" method="POST">
  148. Send this file: <input name="upfile" type="file">
  149. <input type="submit" value="Send">
  150. </form>
  151. <form enctype="multipart/form-data" action="index.php" method="POST">
  152. Get this URL(s):
  153.     <textarea name="url" cols="80" rows="5"></textarea>
  154. <input type="submit" value="Get">
  155. </form>
  156. <?php } else { ?>
  157. <br><span><?php echo "Exceeded maximum disk space quota! ({$max})"; ?></span><br>
  158. <?php } ?>
  159. </body>
  160. </html>
  161. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment