可怕的“警告:imagecreatefromjpeg() : '/tmp/filename' 在第 xxx 行的 /phpfile.php 中不是有效的 JPEG 文件”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3901455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
the dreaded "Warning: imagecreatefromjpeg() : '/tmp/filename' is not a valid JPEG file in /phpfile.php on line xxx"
提问by Sherif Buzz
I've been getting this warning when some people upload images to our site :
当有些人将图片上传到我们的网站时,我收到了这个警告:
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /home/pathremoved/includes/snapsutils.php on line 220
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/tmp/phpiw4MFk' is not a valid JPEG file in /home/pathremoved.php on line 220
Warning: imagesx(): supplied argument is not a valid Image resource in /home/pathremoved.php on line 222
Warning: imagesy(): supplied argument is not a valid Image resource in /home/pathremoved.php on line 223
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/pathremoved.php on line 240
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/pathremoved.php on line 242
警告:imagecreatefromjpeg() [function.imagecreatefromjpeg]:gd-jpeg:JPEG 库报告不可恢复的错误:在第 220 行的 /home/pathremoved/includes/snapsutils.php
警告:imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/tmp/phpiw4MFk' 不是第 220 行 /home/pathremoved.php 中的有效 JPEG 文件
警告:imagesx():提供的参数不是第 222 行 /home/pathremoved.php 中的有效图像资源
警告:imagesy():提供的参数不是第 223 行 /home/pathremoved.php 中的有效图像资源
警告:imagecreatetruecolor() [function.imagecreatetruecolor]:第 240 行 /home/pathremoved.php 中的图像尺寸无效
警告:imagecopyresampled():提供的参数不是第 242 行 /home/pathremoved.php 中的有效图像资源
This only happens with certain images, which when opened in any program are ok, it even uploads to the version of the site I have on localhost with no problems...I googled a bit but found nothing conclusive...
这只发生在某些图像上,在任何程序中打开时都可以,它甚至可以上传到我在本地主机上的站点版本,没有问题......我用谷歌搜索了一下,但没有找到任何结论......
note php upload_max size is 5M and post_max_size is 5M. This is not an upload or memory issue. I've tested with 4M images without problems.
注意 php upload_max 大小为 5M,post_max_size 为 5M。这不是上传或内存问题。我已经用 4M 图像进行了测试,没有问题。
any help appreciated.
任何帮助表示赞赏。
回答by Jeremy
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:
在谷歌上稍微挖掘之后,我发现了这个错误报告。与其他程序相比,GD 库似乎对有缺陷的 JPEG 文件的容忍度更低。建议的解决方案是在处理图像之前将 GD 设置为忽略 JPEG 错误,如下所示:
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.
希望这对你有用。您可能遇到的另一个潜在问题是内存。一旦打开,GD 似乎将所有图像作为位图保存在内存中。这意味着 5MB 的图像实际上可以消耗比单个 PHP 线程允许的更多的内存,从而导致致命错误。我在上传一些图片时遇到了这个问题,并且不得不减小我允许的最大文件大小来解决这个问题。
Good luck and hope that helps.
祝你好运,希望有所帮助。
回答by StarSagar
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...:)
希望这对你有帮助...:)
回答by ilcartolaio
This image cause a never-ending request to the server in Firefox (3.6.10). Firefox says it contains errors.
此图像在 Firefox (3.6.10) 中导致对服务器的永无止境的请求。Firefox 说它包含错误。