the dreaded “Warning: imagecreatefromjpeg() : '/tmp/filename' is not a valid JPEG file in /phpfile.php on line xxx”

后端 未结 3 1810
后悔当初
后悔当初 2020-12-03 12:40

I\'ve been getting this warning when some people upload images to our site :

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpe

相关标签:
3条回答
  • 2020-12-03 13:00

    This image cause a never-ending request to the server in Firefox (3.6.10). Firefox says it contains errors.

    0 讨论(0)
  • 2020-12-03 13:16

    After a little digging around on Google I found this bug report. It seems that the GD library is less tolerant of buggy JPEG files than other programs. The solution suggested was to set GD to ignore JPEG error's before processing the image, like this:

    ini_set("gd.jpeg_ignore_warning", 1);
    

    Hopefully that will work for you. One other potential problem you may run into is to do with memory. It seems that GD holds all images in memory as bitmaps once they've been opened. This means that a 5MB image can actually consume more memory than a single PHP thread is allowed, resulting in a fatal error. I had this problem with some image uploads and had to reduce the maximum file size I allowed to get around the problem.

    Good luck and hope that helps.

    0 讨论(0)
  • 2020-12-03 13:16

    I also face same issue.

    we used below code to fix this issue and it works for me,

    ...
    $image = @ImageCreateFromJpeg($image_name);
    if (!$image)
    {
       $image= imagecreatefromstring(file_get_contents($image_name));
    }
    ...
    

    Hope this helps you...:)

    0 讨论(0)
提交回复
热议问题