lamiastella

upload.php

Sep 20th, 2016
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1. <?php
  2. $target_dir = "uploads/";
  3. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  4. $uploadOk = 1;
  5. $fileType = pathinfo($target_file,PATHINFO_EXTENSION);
  6. // Check if image file is a actual image or fake image
  7. if(isset($_POST["submit"])) {
  8.     //$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  9.     $check = filesize($_FILES["fileToUpload"]["tmp_name"]);
  10.     if($check !== false) {
  11.         echo "This is a CSV format file - " . $check["mime"] . ".";
  12.         $uploadOk = 1;
  13.     } else {
  14.         echo "This is not a CSV format file.";
  15.         $uploadOk = 0;
  16.     }
  17. }
  18. // Check if file already exists
  19. if (file_exists($target_file)) {
  20.     echo "File already exists! Upload a new file";
  21.     $uploadOk = 0;
  22. }
  23. // Check file size
  24. //check with WonHwa, what size limit are we looking at?
  25. if ($_FILES["fileToUpload"]["size"] > 500000) {
  26.     echo "Sorry, your file is too large.";
  27.     $uploadOk = 0;
  28. }
  29. // Allow certain file formats
  30. //if($imageFileType != "csv" && $imageFileType != "png" && $imageFileType != "jpeg"
  31. //&& $imageFileType != "gif" ) {
  32. if($fileType != "csv" ) {
  33.     echo "Sorry! Only CSV files can be uploaded!!";
  34.     $uploadOk = 0;
  35. }
  36. // Check if $uploadOk is set to 0 by an error
  37. if ($uploadOk == 0) {
  38.     echo "Sorry, your file was not uploaded.";
  39. // if everything is ok, try to upload file
  40. } else {
  41.     if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  42.         echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  43.     } else {
  44.         echo "Sorry, there was an error uploading your file.";
  45.     }
  46. }
  47.  
  48. ?>
Add Comment
Please, Sign In to add comment