How to prevent having the “is not a valid image file” error when using GD function imagecreatefrom* in php?
问题 I am using imagecreatefromgif / imagecreatefromjpeg / imagecreatefromjpeg functions with uploaded images and sometimes get an error (e.g. Warning: imagecreatefromgif(): ... is not a valid GIF file) when the image is corrupted. I read lots of posts about this topic and couldn't find a "working" answer. I did try some of the following to validate the image (as suggested on other posts) but none of them worked in ALL situations. If the image does not have the header info, the following works,