daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. // Upload and Rename File
  4.  
  5. if (isset($_POST['submit']))
  6. {
  7.     $filename = $_FILES["file"]["name"];
  8.     $file_basename = substr($filename, 0, strripos($filename, '.')); // get file extention
  9.     $file_ext = substr($filename, strripos($filename, '.')); // get file name
  10.     $filesize = $_FILES["file"]["size"];
  11.     $allowed_file_types = array('.doc','.docx','.rtf','.pdf'); 
  12.  
  13.     if (in_array($file_ext,$allowed_file_types) && ($filesize < 200000))
  14.     {  
  15.         // Rename file
  16.         $newfilename = md5($file_basename) . $file_ext;
  17.         if (file_exists("upload/" . $newfilename))
  18.         {
  19.             // file already exists error
  20.             echo "You have already uploaded this file.";
  21.         }
  22.         else
  23.         {      
  24.             move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $newfilename);
  25.             echo "File uploaded successfully.";    
  26.         }
  27.     }
  28.     elseif (empty($file_basename))
  29.     {  
  30.         // file selection error
  31.         echo "Please select a file to upload.";
  32.     }
  33.     elseif ($filesize > 200000)
  34.     {  
  35.         // file size error
  36.         echo "The file you are trying to upload is too large.";
  37.     }
  38.     else
  39.     {
  40.         // file type error
  41.         echo "Only these file typs are allowed for upload: " . implode(', ',$allowed_file_types);
  42.         unlink($_FILES["file"]["tmp_name"]);
  43.     }
  44. }
  45.  
  46. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top