Advertisement
Guest User

upload.php

a guest
Feb 2nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. <?php
  2. function createFile($filename, $content) {
  3.     $myfile = fopen($filename, "w") or die("cannot open file");
  4.     fwrite($myfile, $content);
  5.     fclose($myfile);
  6. }
  7. function createDir($dir) {
  8.     if (!file_exists($dir)) {
  9.         mkdir($dir, 0777, true);
  10.     }
  11. }
  12. function generatePostUploadPage($id, $filename, $originalfilename, $adultcontent, $dh, $sz, $outfile) {
  13.     $myFile = $outfile; // or .php  
  14.     $fh = fopen($myFile, 'w'); // or die("error");  
  15.     $stringData = "
  16. <body>
  17.     <center>
  18.         <br>
  19.         <a href=\"/\">Go to home page</a>
  20.         <br>
  21.         <img src=\"/logo.png\" alt=\"Logo\" style=\"width:256px;height:256px;\">
  22.         <h2>The Hidden Hosting</h2>
  23.         <h5>Free and anonymous file hosting</h5>
  24.         <hr>
  25.        
  26.         <a>ID:</a>
  27.         <br>
  28.         <b>".$id."</b>
  29.         <br>
  30.         <br>
  31.        
  32.         <a>Filename and size:</a>
  33.         <br>
  34.         <b>".$originalfilename.' ('.$sz.')'."</b>
  35.         <br>
  36.         <br>
  37.        
  38.         <a>Contains adult content:</a>
  39.         <br>
  40.         <b>".$adultcontent."</b>
  41.         <br>
  42.         <br>
  43.        
  44.         <a>Upload date:</a>
  45.         <br>
  46.         <b>GMT+0 ".$dh."</b>
  47.         <br>
  48.         <br>
  49.        
  50.         <a href='".$filename."'>Download file</a> <br><br>
  51.         <a href='/delete.php?id=".$id."'>Delete</a>
  52.     </center>
  53. </body>";
  54.     fwrite($fh, $stringData);
  55. }
  56.  
  57. function formatBytes($bytes, $precision = 2) {
  58.     $units = array('B', 'KB', 'MB', 'GB', 'TB');
  59.    
  60.     $bytes = max($bytes, 0);
  61.     $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
  62.     $pow = min($pow, count($units) - 1);
  63.    
  64.     $bytes /= pow(1024, $pow);
  65.    
  66.     return round($bytes, $precision) . ' ' . $units[$pow];
  67. }
  68. function generateRandomString($length = 10) {
  69.     $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
  70.     $charactersLength = strlen($characters);
  71.     $randomString = '';
  72.     for ($i = 0; $i < $length; $i++) {
  73.         $randomString .= $characters[rand(0, $charactersLength - 1)];
  74.     }
  75.     return $randomString;
  76. }
  77. if(isset($_POST['btn-upload']))
  78. {
  79.     $original = $_FILES['pic']['name'];
  80.     $array = explode('.', $original);
  81.     $extension = end($array);
  82.     $id = generateRandomString(16);
  83.     $pic = $id.'.'.$extension;
  84.     $pic_loc = $_FILES['pic']['tmp_name'];
  85.     $folder="uploaded/".$id."/";
  86.     createDir($folder);
  87.     $size = "";
  88.     $outfile = $folder.$pic;
  89.    
  90.     $postpage = $folder.'download.html';
  91.    
  92.     $adult = isset($_POST['adultcontent']) && $_POST['adultcontent']  ? "Yes" : "No";
  93.    
  94.     $now = date("Y/m/d - h:i:s");
  95.    
  96.     $deletepw = $_POST['deletepw'];
  97.    
  98.     if(move_uploaded_file($pic_loc, $outfile))
  99.     {
  100.         $size = formatBytes(filesize($folder . $pic));
  101.         generatePostUploadPage($id, $pic, $original, $adult, $now, $size, $postpage);
  102.         createFile($folder . ".deletepw", $deletepw);
  103.        
  104.         ?>
  105.         <br>
  106.         <!--<script>alert('successfully uploaded to <?php echo $pic?>');</script>-->
  107.         <center><a href="http://hiddenhosting.66ghz.com/<?php echo $postpage;?>"><font size="4" color="blue">Click here to see your uploaded file <?php echo ' (' . $size . ')';?></font></a></center>
  108.        
  109.         <?php
  110.     }
  111.     else
  112.     {
  113.         ?><script>alert('error');</script><?php
  114.     }
  115. }
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement