Advertisement
bala150985

php file upload

May 23rd, 2015
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. $ cat pv.html
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5. <body>
  6.  
  7. <form action="upload.php" method="post" enctype="multipart/form-data">
  8. Select image to upload:
  9. <input type="file" name="fileToUpload" id="fileToUpload">
  10. <input type="submit" value="Upload Image" name="submit">
  11. </form>
  12.  
  13. </body>
  14. </html>
  15.  
  16.  
  17. $ cat upload.php
  18.  
  19. <?php
  20. $target_dir = "/var/www/uploads/";
  21. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  22. $uploadOk = 1;
  23. $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  24.  
  25. echo "The value of target directory is =" . $target_dir . "</br>";
  26. echo "The value of target file is =" . $target_file . "</br>";
  27. echo "The value of uploadOk is =" . $uploadOk . "</br>";
  28. echo "The value of imageFileType is =" . $imageFileType . "</br>";
  29.  
  30. echo "Upload: " . $_FILES["fileToUpload"]["name"] . "<br />";
  31. echo "Type: " . $_FILES["fileToUpload"]["type"] . "<br />";
  32. echo "Size: " . ($_FILES["fileToUpload"]["size"] / 1024) . " Kb<br />";
  33. echo "Temp file: " . $_FILES["fileToUpload"]["tmp_name"] . "<br />";
  34. echo "Error :" . $_FILES["fileToUpload"]["error"] . "<br / >";
  35.  
  36.  
  37. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  38. echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  39. } else {
  40. echo "Sorry, there was an error uploading your file.";
  41. }
  42.  
  43. $finfo = finfo_open(FILEINFO_MIME_TYPE);
  44.  
  45. echo "</br> The value of finfo is =" . $finfo . "</br>";
  46. echo finfo_file($finfo, $target_file );
  47. finfo_close($finfo);
  48.  
  49. ?>
  50.  
  51.  
  52. Reference
  53.  
  54.  
  55. http://php.net/manual/en/features.file-upload.php
  56.  
  57.  
  58. To find out error codes.
  59.  
  60. http://php.net/manual/en/features.file-upload.errors.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement