getimagesize() 对某些图像返回 false

发布于 2024-08-10 09:23:36 字数 1470 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

淡写薰衣草的香 2024-08-17 09:23:36

在你提供更多信息之前,我真的帮不了什么忙。以下代码:(

$file = "http://img27.imageshack.us/img27/9159/dsc00799e.jpg";
$info = getimagesize($file);

echo "<pre>" . print_r($info,true) . "</pre>";

其中 $file 等于问题中给出的图像的位置),输出:

Array
(
    [0] => 2736
    [1] => 3648
    [2] => 2
    [3] => width="2736" height="3648"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)

这看起来没问题。我假设您的支票中其他地方有错误?

Until you give more information, I can't really help much. The following code:

$file = "http://img27.imageshack.us/img27/9159/dsc00799e.jpg";
$info = getimagesize($file);

echo "<pre>" . print_r($info,true) . "</pre>";

(Where $file is equal to the location of the image given in the question), outputs:

Array
(
    [0] => 2736
    [1] => 3648
    [2] => 2
    [3] => width="2736" height="3648"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)

This seems okay. I'm assuming an error somewhere else in your checks?

苦妄 2024-08-17 09:23:36

环顾四周后,我发现了这个关于PHP 的上传限制。我将它与我已经知道的内容结合起来,最后在我的 .htaccess 中使用以下代码使其正常工作(将上传限制为 5MB):

php_value upload_max_filesize 5M
php_value post_max_size 8M
php_value max_input_time 1800
LimitRequestBody 0

底线是:问题不在 PHP 的 getimagesize() 函数中,由于 Apache 和 PHP 中的文件大小限制,图像从未上传到服务器。感谢所有回答和评论的人,如果没有你们的帮助,弄清楚这个问题会更加痛苦!

After looking around SO I've found this insightful answer regarding PHP's upload limits. I combined it with what I already knew and finally got it working using the following code in my .htaccess (limiting uploads to 5MB):

php_value upload_max_filesize 5M
php_value post_max_size 8M
php_value max_input_time 1800
LimitRequestBody 0

Bottom line is: the problem wasn't in PHP's getimagesize() function, it was that the images were never uploaded to the server due to file size limits in both Apache and PHP. Thanks everyone who answered and commented, It would have been a lot more painful to figure it out without your help!

雄赳赳气昂昂 2024-08-17 09:23:36

我不确定这是否是您正在寻找的答案,但我知道我对 php 函数和任何尺寸超过 3000px 的图像都有问题。

希望有帮助!

I am not sure if this is the answer your looking for but I know that I have issues with php functions and images being over 3000px in any dimension.

Hope that helps!

热血少△年 2024-08-17 09:23:36

你说

$_FILES 似乎为空

您检查上传错误吗? - 当上传失败时,PHP 设置文件数组的 error 元素。有关不同错误,请参阅 PHP 文档的文件上传部分代码可能。

You said

$_FILES seems to be empty

Did you check for an upload error? - When the upload fails PHP sets the error element of the file's array. See the PHP documentation's File Upload section for different error codes possible.

青春有你 2024-08-17 09:23:36

我遇到了同样的问题,我使用了与 img 标签中使用的完全相同的文件引用:

  $filename = "/images/logo.jpg"; 

  $size = getimagesize($filename); // <== this fails

  <img src="<?echo $filename ?>" />  // <== this works

当我删除文件名中的第一个斜杠并再次尝试时,它起作用了:

  $size = getimagesize("/images/logo.jpg"); // <== this fails

  $size = getimagesize("images/logo.jpg"); // <== this works!

我希望它也适用于其他人。

I faced the same problem, i used exactly the same file reference as used in the img tag:

  $filename = "/images/logo.jpg"; 

  $size = getimagesize($filename); // <== this fails

  <img src="<?echo $filename ?>" />  // <== this works

When I removed the first slash in the file name and tried it again, it worked:

  $size = getimagesize("/images/logo.jpg"); // <== this fails

  $size = getimagesize("images/logo.jpg"); // <== this works!

I hope it works for others too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文