Advertisement
Guest User

Untitled

a guest
Sep 5th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <?php
  2.  
  3. $target_dir = "uploads/";
  4. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  5. $uploadOk = 1;
  6. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  7. if(isset($_POST["submit"])) {
  8. $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  9. if($check !== false) {
  10. echo "File is an image - " . $check["mime"] . ".";
  11. $uploadOk = 1;
  12. } else {
  13. echo "File is not an image.";
  14. $uploadOk = 0;
  15. }
  16. }
  17.  
  18. if ($_FILES["fileToUpload"]["size"] > 500000) {
  19. echo "Sorry, your file is too large.";
  20. $uploadOk = 0;
  21. }
  22.  
  23. if($imageFileType != "jpg" ) {
  24. echo "Only jpg";
  25. $uploadOk = 0;
  26. }
  27.  
  28. if ($uploadOk == 0) {
  29. echo "Sorry, your file was not uploaded.";
  30.  
  31. } else {
  32. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  33. echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  34. } else {
  35. echo "Sorry, there was an error uploading your file.";
  36. }
  37. }
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement