Advertisement
phirani

Upload Processing Coding

Dec 19th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <?php
  2. $target_dir = "uploads/file_name";
  3. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  4. $uploadOk = 1;
  5.  
  6. // Check if file already exists
  7. if (file_exists($target_file)) {
  8. echo "Sorry, file already exists.";
  9. $uploadOk = 0;
  10. }
  11. // Check file size
  12. if ($_FILES["fileToUpload"]["size"] > 500000) {
  13. echo "Sorry, your file is too large.";
  14. $uploadOk = 0;
  15. }
  16. // Allow certain file formats
  17.  
  18. // Check if $uploadOk is set to 0 by an error
  19. if ($uploadOk == 0) {
  20. echo "Sorry, your file was not uploaded.";
  21. // if everything is ok, try to upload file
  22. } else {
  23. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  24. echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  25. } else {
  26. echo "Sorry, there was an error uploading your file.";
  27. }
  28. }
  29.  
  30. ?>
  31.  
  32. <html>
  33.  
  34. <h1><li class ="active"><a href="Home.php">Home</a></li> </h1>
  35. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement