You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

upload_picture.php 1.3 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8. <head>
  9. <meta charset="UTF-8">
  10. <title>Upload</title>
  11. </head>
  12. <body>
  13. <?php
  14. if (isset($_FILES["file"]["name"])) {
  15. $name = $_FILES["file"]["name"];
  16. $temp_file = $_FILES['file']['tmp_name'];
  17. $error = $_FILES['file']['error'];
  18. $imginfo_array = getimagesize($temp_file); // returns a false if not a valid image file
  19. if ($imginfo_array !== false) {
  20. $mime_type = $imginfo_array['mime'];
  21. switch($mime_type) {
  22. case "image/jpeg" ||"image/gif" || "image/png":
  23. $location = 'pictures/';
  24. move_uploaded_file($temp_file, $location.$name);
  25. echo 'Uploaded successfully.';
  26. }
  27. }
  28. else {
  29. echo "This is not a valid image file";
  30. }
  31. }
  32. ?>
  33. <form action="upload_picture.php" method="POST" enctype="multipart/form-data">
  34. <input type="file" name="file"><br><br>
  35. <input type="submit" value="Submit">
  36. </form>
  37. </body>
  38. </html>

No Description

Contributors (1)