Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. session_start();
  3.  
  4. /* Define settings */
  5.  
  6. $siteTITLE="File Upload"; // title of site
  7. $siteHEADER="File Upload"; // header text
  8. $siteFOOTER="Created by Techno"; // footer text
  9. $allowed_extensions=array("zip","rar","png"); // allowed extensions
  10. $upload_destination="files"; // path to directory where files would be saved
  11. $protected=1; // 0 or 1 [ If protected is set to 1, then define $key as your secret key. ]
  12. $key="admin"; // secret key to access uploader in case protected is set to 1
  13.  
  14. /* DO NOT EDIT BELOW */
  15.  
  16. $file=basename(__FILE__);
  17. $max_size_allowed=2*(1024*1024); // 2 MB
  18. $allowed=join(",",$allowed_extensions);
  19. $max=size($max_size_allowed);
  20. if($protected)$logout="<div align='right'><a href='$file?logout=true'>Logout</a></div>";else$logout="";
  21.  
  22. /* Authentication begins */
  23.  
  24. if($protected==1){
  25.     if(isset($_GET['logout'])){
  26.         unset($_SESSION['uploader_allowed']);
  27.         header("Location: $file");
  28.         exit;
  29.     }
  30.     if(!isset($_SESSION['uploader_allowed'])){
  31.         if(isset($_POST['submit'])){
  32.             if($_POST['key']==$key){
  33.                 $_SESSION['uploader_allowed']=1;
  34.                 header("Location: $file");
  35.                 exit;
  36.             }
  37.             else{header("Location: $file");}
  38.         }
  39.         else{
  40.             echo"<form method='post' action='$file'>SecretKey : <input type='text' name='key' value='' /> <input type='submit' name='submit' value='Go' /></form>";
  41.         }
  42.         exit;
  43.     }
  44. }
  45.  
  46. /* Authentication ends */
  47.  
  48. function size($size,$round=1){
  49.     $sizes = array(' Byts', ' Kb', ' Mb', ' Gb',' TB');
  50.     $total = count($sizes)-1;
  51.     for ($i=0; $size > 1024 && $i < $total; $i++)
  52.         $size /= 1024;
  53.     return round($size,$round).$sizes[$i];
  54. }
  55.  
  56. /* Iframe begins */
  57.  
  58. if(isset($_GET['frame']) && $_GET['frame']==true){
  59. echo"
  60. <html>
  61. <head>
  62. <title></title>
  63. <style type='text/css'>
  64. body{color:black;font:11px verdana;}
  65. a:link,a:active,a:visited{color:inherit;text-decoration:none}
  66. a:hover{text-decoration:underline;}
  67. </style>
  68. </title>
  69. </head>
  70. <body>
  71. ";
  72.  
  73. if(isset($_POST['submit']) && $_POST['submit']=="Upload"){
  74.     $file=$_FILES['file'];
  75.     if(!empty($file) && $file['error']==0 && $file[size]>0){
  76.         if($file['size']<=$max_size_allowed){
  77.         $ext=strtolower(end(explode(".",$file['name'])));
  78.         $name=str_replace('.','-',substr($file['name'],0,strrpos($file['name'],'.')));
  79.             if(in_array($ext,$allowed_extensions,true)){
  80.                 if(is_dir($upload_destination)){
  81.                 $new="$upload_destination/$name.$ext";
  82.                     if(move_uploaded_file($file['tmp_name'],$new)){
  83.                         $size=size($file[size]);
  84.                         $new = htmlspecialchars($new);
  85.                         $newname=htmlspecialchars(basename($new));
  86.                         echo"<a href='$new'>$newname</a> ( $size )";
  87.                     }else{echo"File upload error. Unable to move to destination folder.";}
  88.                 }else{echo"Destination directory is not a valid directory.";}
  89.             }else{echo"This file extension is not allowed.";}
  90.         }else{echo"File size exceeds maximum upload limit.";}
  91.     }else{echo"There was error while uploading.";}
  92.     sleep(1); // Timelock: just for anim !
  93. }
  94. else{
  95. echo"
  96. <script type='text/javascript'>
  97. function dosubmit()
  98. {
  99. document.getElementsByTagName(\"form\")[0].style.visibility=\"hidden\";
  100. document.getElementsByTagName(\"input\")[1].click();
  101. document.getElementsByTagName(\"img\")[0].style.visibility=\"visible\";
  102. }
  103. </script>
  104.  
  105. <form method='post' action='$file?frame=true' enctype='multipart/form-data'>
  106. <img src='anim.gif' id='anim' style='z-index:1;position:absolute;visibility:hidden;' />
  107. <input type='file' name='file' onchange='dosubmit();' />
  108. <input type='submit' name='submit' value='Upload' />
  109. </form>
  110. ";
  111. }
  112.  
  113. exit("</body></html>");
  114. }
  115.  
  116. $var=<<<UNCOMPLICATED
  117. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  118. <html xmlns="http://www.w3.org/1999/xhtml">
  119. <head>
  120. <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1;charset=windows-1252' />
  121. <style type="text/css">
  122. body{margin:auto;width:700px;font:11px verdana;line-height:2;}
  123. iframe{border:0px;height:50px;width:700px;}
  124. .header{text-align:center;font:bold 40px cursive;color:rgb(155,155,155);padding:5px;text-shadow:1px 1px 1px rgb(0,0,0);}
  125. .footer{text-align:right;padding:10px;font:10px verdana;}
  126. .info{padding:10px;text-shadow:1px 1px 0.4px rgb(240,240,240);}
  127. .func{text-align:right;padding:10px;}
  128. </style>
  129. <script type='text/javascript'>
  130. function addFrame()
  131. {
  132. var frame = document.createElement('iframe');
  133. frame.setAttribute('src','$file?frame=true');
  134. frame.setAttribute('scrolling','no');
  135. document.getElementById('uploader').appendChild(frame);
  136. }
  137. function clear()
  138. {
  139. document.getElementById('main').innerHTML="<div id='uploader'><iframe src='$file?frame=true' scrolling='no'></iframe></div>";
  140. }
  141. </script>
  142. <title>$siteTITLE</title>
  143. </head>
  144. <body>
  145. <div class='header'><a href='$file'>$siteHEADER</a></div>
  146. $logout
  147. <div class='info'>
  148. &raquo; Maximum upload limit : $max
  149. <br />&raquo; Allowed Extensions : $allowed
  150. </div>
  151. <div id='main'>
  152. <div id='uploader'>
  153. <iframe src='$file?frame=true' scrolling='no'></iframe>
  154. </div>
  155. </div>
  156. <div class='func'><a href='javascript:addFrame();' >Add new</a> <a href='javascript:clear();'>Clear</a></div>
  157. <div class='footer'>$siteFOOTER</div>
  158. UNCOMPLICATED;
  159.  
  160. echo $var;
  161.  
  162. ?>
  163. </body>
  164. </html>