如何处理因上传有问题的 JPEG 而导致的错误?
我有一个公众可以上传 JPEG 的网站。
有人上传了无效的 JPEG,导致网站崩溃。
PHP 说...
imagecreatefromjpeg() [function.imagecreatefromjpeg]:gd-jpeg、libjpeg:可恢复错误:JPEG 文件过早结束
我不确定如何解决这个问题,所以我在 Google 上搜索并找到 此网站。它告诉我添加...
ini_set('gd.jpeg_ignore_warning', 1);
我在我的 index.php
(我网站的引导程序,我在其中执行其他 ini_set()
)中添加了它。
这似乎并没有解决它。
我该如何处理这种无效 JPEG 的情况?我对 INI 集做错了什么吗?我位于共享主机上,因此无法直接更改 php.ini
。
我正在使用 Kohana 2.3 及其 图像库,但我不认为它是这里确实相关。
I have a website where the public can upload JPEGs.
Someone from the public was uploading an invalid JPEG that was causing the site to crash for them.
PHP said...
imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file
I wasn't sure how to get around this, so I Googled and found this site. It told me to add...
ini_set('gd.jpeg_ignore_warning', 1);
I added that in my index.php
(the bootstrap of my site, where I do other ini_set()
).
This didn't seem to fix it.
How can I handle this case of invalid JPEGs? Am I doing something wrong with the INI set? I'm on a shared host so I can't change php.ini
directly.
I'm using Kohana 2.3, and its Image library, but I don't think it is really relevant here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您通常会像这样使用
imagecreatefromjpeg
:请注意
imagecreatefromjpeg
前面的@
,它用于抑制错误。不幸的是,我无法告诉您 Kohana 内部是如何做到这一点的,以及是否可以说服它做同样的事情。You would usually work with
imagecreatefromjpeg
like this:Note the
@
in front ofimagecreatefromjpeg
, which is used to suppress errors. Unfortunatly I can't tell you how Kohana does this internally and if it could be persuaded to do the same thing.尝试在命令前添加一个
@
字符:它很脏并且可能已经过时(更不用说慢),但它可能会使您的代码不会失败。
希望这有帮助!
Try sticking an
@
character before the command:It's dirty and probably obsolete (not to mention slow), but it'll probably make your code not fail.
Hope this helps!