Advertisement
umasoodch

php file for uploading files

Dec 19th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4. $dir_path='FilesUploading/' . $_SESSION['user_name'] . '/' . $file;
  5.  
  6. $target_file = $dir_path . basename($_FILES["fileToUpload"]["name"]);
  7. $uploadOk = 1;
  8. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  9. // Check if image file is a actual image or fake image
  10. if(isset($_POST["submit"])) {
  11. $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  12. $uploadOk = 1;
  13. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  14. // Check if image file is a actual image or fake image
  15. if(isset($_POST["submit"])) {
  16. $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  17.  
  18. }
  19.  
  20. if (file_exists($target_file)) {
  21. echo "Sorry, file already exists.";
  22. $uploadOk = 0;
  23. }
  24.  
  25. if ($_FILES["fileToUpload"]["size"] > 500000) {
  26. echo "Sorry, your file is too large.";
  27. $uploadOk = 0;
  28. }
  29.  
  30.  
  31. if ($uploadOk == 0) {
  32. echo "Sorry, your file was not uploaded.";
  33. // if everything is ok, try to upload file
  34. } else {
  35. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  36. echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  37. } else {
  38. echo "Sorry, there was an error uploading your file.";
  39. }
  40.  
  41. }
  42. }
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement