SHARE
TWEET

Untitled

a guest Dec 9th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  <?php
  2. session_start();
  3. echo $random_name= $_SESSION['upload_id'];
  4.     ?>
  5.  
  6.    <form action="uploader_file.php" method="post" enctype="multipart/form-data">
  7.         <label for="fileSelect">Filename:</label>
  8.         <input type="file" name="photo" id="fileSelect">
  9.         <input type="submit" name="submit" value="Upload">
  10.         <p><strong>Note:</strong> Only .pdf allowed to a max size of 5 MB.</p>
  11.     </form>
  12.  
  13. <?php
  14.  
  15. // Check if the form was submitted
  16. if($_SERVER["REQUEST_METHOD"] == "POST"){
  17.  
  18.     // Check if file was uploaded without errors
  19.     if(isset($_FILES["photo"]) && $_FILES["photo"]["error"] == 0){
  20.         $allowed = array("pdf" => "application/pdf");
  21.         $filename = $_FILES["photo"]["name"];
  22.         $filetype = $_FILES["photo"]["type"];
  23.         $filesize = $_FILES["photo"]["size"];
  24.    
  25.         // Verify file extension
  26.         $ext = pathinfo($filename, PATHINFO_EXTENSION);
  27.         if(!array_key_exists($ext, $allowed)) die("Error: Please select a valid file format.");
  28.    
  29.         // Verify file size - 5MB maximum
  30.         $maxsize = 5 * 1024 * 1024;
  31.         if($filesize > $maxsize) die("Error: File size is larger than the allowed limit.");
  32.    
  33.         // Verify MYME type of the file
  34.         if(in_array($filetype, $allowed)){
  35.             // Check whether file exists before uploading it
  36.             if(file_exists("../download/" . $filename)){
  37.                 echo $filename . " is already exists.";
  38.             } else{
  39.                 move_uploaded_file($_FILES["photo"]["tmp_name"], "../download/upload/" . $filename);
  40.                 echo "Your file was uploaded successfully.";
  41.             }
  42.         } else{
  43.             echo "Error: There was a problem uploading your file. Please try again.";
  44.         }
  45.     } else{
  46.         echo "Error: " . $_FILES["photo"]["error"];
  47.     }
  48. }
  49. ?>
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top