Php upload image to directory

后端 未结 6 390
野的像风
野的像风 2021-01-13 16:25

Ive been experimenting with the upload capability of php, I have been looking at this tutorial on w3school.

http://www.w3schools.com/php/php_file_upload.asp
         


        
6条回答
  •  悲哀的现实
    2021-01-13 17:10

    Your validation code is checking the extension, mime type and file size.

    You are probably uploading a file with uppercase characters in the extension. When you check the extension, you checking it case sensitive, .JPG is a valid image file extension, so you should make your check case insensitive:

    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/png")
    || ($_FILES["file"]["type"] == "image/pjpeg"))
    && ($_FILES["file"]["size"] < 20000)
    && in_array(strtolower($extension), $allowedExts))
             // ^ added strtolower()
    

    If that isn't the immediate problem then the file is too big or has the wrong mime type. To debug, view the files array with:

    print_r($_FILES);
    

提交回复
热议问题