Advertisement
Guest User

Untitled

a guest
Oct 26th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <?php
  2. $target_dir = "";
  3. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  4. $uploadOk = 1;
  5. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  6. // Check if image file is a actual image or fake image
  7. if(isset($_POST["submit"])) {
  8. }
  9. // Check if file already exists
  10. if (file_exists($target_file)) {
  11. echo "Sorry, file already exists.";
  12. $uploadOk = 0;
  13. }
  14. // Check file size
  15. if ($_FILES["fileToUpload"]["size"] > 50000) {
  16. echo "Sorry, your file is too large.";
  17. $uploadOk = 0;
  18. }
  19. // Allow certain file formats
  20. if($imageFileType != "txt" ) {
  21. echo "Sorry, only TXT files are allowed.";
  22. $uploadOk = 0;
  23. }
  24.  
  25. // Check if $uploadOk is set to 0 by an error
  26. if ($uploadOk == 0) {
  27. echo "Sorry, your file was not uploaded.";
  28. // if everything is ok, try to upload file
  29. } else {
  30. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  31. echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  32. rename ("$_FILES.txt", "$_FILES.html");
  33. } else {
  34. echo "Sorry, there was an error uploading your file.";
  35. }
  36. }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement