Guest User

Untitled

a guest
Jun 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. $target_dir = "./uploads/";
  2. $target_file = $target_dir . basename($_FILES["image"]["name"]);
  3. $uploadOk = 1;
  4. $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
  5. // Check if image file is a actual image or fake image
  6. if(isset($_POST["submit"])) {
  7. $check = getimagesize($_FILES["image"]["tmp_name"]);
  8. if($check !== false) {
  9. echo "File is an image - " . $check["mime"] . ".";
  10. $uploadOk = 1;
  11. } else {
  12. echo "File is not an image.";
  13. $uploadOk = 0;
  14. }
  15. }
  16. // Check if file already exists
  17. if (file_exists($target_file)) {
  18. echo "Sorry, file already exists.";
  19. $uploadOk = 0;
  20. }
  21. // Check file size
  22. if ($_FILES["image"]["size"] > 500000) {
  23. echo "Sorry, your file is too large.";
  24. $uploadOk = 0;
  25. }
  26. // Allow certain file formats
  27. if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
  28. && $imageFileType != "gif" ) {
  29. echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  30. $uploadOk = 0;
  31. }
  32. // Check if $uploadOk is set to 0 by an error
  33. if ($uploadOk == 0) {
  34. echo "Sorry, your file was not uploaded.";
  35. // if everything is ok, try to upload file
  36. } else {
  37. // if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
  38. // echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.";
  39. // } else {
  40. // echo "Sorry, there was an error uploading your file.";
  41. // }
  42. }
  43.  
  44.  
  45. move_uploaded_file($_FILES["image"]["tmp_name"],"./uploads/" . $_FILES["image"]["name"]);
  46. $location=$_FILES["image"]["name"];
Add Comment
Please, Sign In to add comment