Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- echo $random_name= $_SESSION['upload_id'];
- ?>
- <form action="uploader_file.php" method="post" enctype="multipart/form-data">
- <label for="fileSelect">Filename:</label>
- <input type="file" name="photo" id="fileSelect">
- <input type="submit" name="submit" value="Upload">
- <p><strong>Note:</strong> Only .pdf allowed to a max size of 5 MB.</p>
- </form>
- <?php
- // Check if the form was submitted
- if($_SERVER["REQUEST_METHOD"] == "POST"){
- // Check if file was uploaded without errors
- if(isset($_FILES["photo"]) && $_FILES["photo"]["error"] == 0){
- $allowed = array("pdf" => "application/pdf");
- $filename = $_FILES["photo"]["name"];
- $filetype = $_FILES["photo"]["type"];
- $filesize = $_FILES["photo"]["size"];
- // Verify file extension
- $ext = pathinfo($filename, PATHINFO_EXTENSION);
- if(!array_key_exists($ext, $allowed)) die("Error: Please select a valid file format.");
- // Verify file size - 5MB maximum
- $maxsize = 5 * 1024 * 1024;
- if($filesize > $maxsize) die("Error: File size is larger than the allowed limit.");
- // Verify MYME type of the file
- if(in_array($filetype, $allowed)){
- // Check whether file exists before uploading it
- if(file_exists("../download/" . $filename)){
- echo $filename . " is already exists.";
- } else{
- move_uploaded_file($_FILES["photo"]["tmp_name"], "../download/upload/" . $filename);
- echo "Your file was uploaded successfully.";
- }
- } else{
- echo "Error: There was a problem uploading your file. Please try again.";
- }
- } else{
- echo "Error: " . $_FILES["photo"]["error"];
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement