Advertisement
Guest User

Untitled

a guest
Jan 17th, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. <?php
  2. // Access the $_FILES global variable for this specific file being uploaded
  3. // and create local PHP variables from the $_FILES array of information
  4. $fileName = $_FILES["uploaded_file"]["name"]; // The file name
  5. $fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder
  6. $fileType = $_FILES["uploaded_file"]["type"]; // The type of file it is
  7. $fileSize = $_FILES["uploaded_file"]["size"]; // File size in bytes
  8. $fileErrorMsg = $_FILES["uploaded_file"]["error"]; // 0 = false | 1 = true
  9. $kaboom = explode(".", $fileName); // Split file name into an array using the dot
  10. $fileExt = end($kaboom); // Now target the last array element to get the file extension
  11. // START PHP Image Upload Error Handling --------------------------------------------------
  12. if (!$fileTmpLoc) { // if file not chosen
  13. echo "ERROR: Please browse for a file before clicking the upload button.";
  14. exit();
  15. } else if($fileSize > 5242880) { // if file size is larger than 5 Megabytes
  16. echo "ERROR: Your file was larger than 5 Megabytes in size.";
  17. unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
  18. exit();
  19. } else if (!preg_match("/.(zip|tar|gz)$/i", $fileName) ) {
  20. // This condition is only if you wish to allow uploading of specific file types
  21. echo "ERROR: Your file was not .zip, .tar, .gz!";
  22. unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
  23. exit();
  24. } else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1
  25. echo "ERROR: An error occured while processing the file. Try again.";
  26. exit();
  27. }
  28. // END PHP Image Upload Error Handling ----------------------------------------------------
  29. // Place it into your "uploads" folder mow using the move_uploaded_file() function
  30. $moveResult = move_uploaded_file($fileTmpLoc, "uploads/$fileName");
  31. // Check to make sure the move result is true before continuing
  32. if ($moveResult != true) {
  33. echo "ERROR: File not uploaded. Try again.";
  34. unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
  35. exit();
  36. }
  37. unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
  38. // Display things to the page so you can see what is happening for testing purposes
  39. echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />";
  40. echo "Your files download link is http://hvgaming.bugs3.com/upload/uploads/$fileName<br />";
  41. echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />";
  42. echo "<a href='http://hvgaming.bugs3.com/upload'>Click here to upload another file!</a>";
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement