Php upload image to directory

后端 未结 6 391
野的像风
野的像风 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:12

    This happens because the following expression evaluates to false:

    (($_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($extension, $allowedExts)
    

    Which means that either

    • The file type is incorrect (it is not a GIF/JPEG/PNG/PNJPEG file)
    • The file is bigger than 20000 bytes
    • The file extension is incorrect (it is not any of "jpg", "jpeg", "gif", "png")

    My guess would be the file size - increase it drastically. Change it to the following to allow sizes up to 10 MB:

    && ($_FILES["file"]["size"] < 10485760)
    

    The best way to see the problem is to add this line to the beginning of your script:

    var_dump($_FILES);
    

提交回复
热议问题