【问题标题】:get image width and height from URL doesn't work从 URL 获取图像宽度和高度不起作用
【发布时间】:2014-07-11 10:35:48
【问题描述】:

我想从 url 获取图像的宽度和高度,但它不起作用。它说

警告:getimagesize(https://scontent-b-sin.xx.fbcdn.net/hphotos-xpa1/t1.0-9/156922_131613136994348_1325598195_n.jpg) [function.getimagesize]:无法打开流:第 4 行 D:\AppServ\www\test\test6.php 中的参数无效

PHP

    $url = "https://scontent-b-sin.xx.fbcdn.net/hphotos-xpa1/t1.0-9/156922_131613136994348_1325598195_n.jpg";
    list($width, $height, $type, $attr) = getimagesize($url);

  echo "Image width " . $width ."<br />";
  echo "Image height " . $height ."<br />";
  echo "Image type " . $type ."<br />";
  echo "Attribute " . $attr ."<br />";

?>

使用我电脑中的路径是可行的。发生了什么事?谢谢。

【问题讨论】:

  • 你能不能查一下phpinfo();上面写着Registered PHP Streams的部分,..必须有以下内容:https, http and compress.zlib,可以肯定的是,你能用图片中的图片测试一下吗与您的 PHP 脚本相同的文件夹并尝试该本地图片?
  • getimagesize 响应非常慢,请尝试以下解决方案。 stackoverflow.com/questions/4635936/…
  • @DanFromGermany 同一文件夹中图像的路径和本地都可以。它不仅适用于来自网络的 URL。

标签: php


【解决方案1】:

首先,要测试文件是否存在,请使用 file_exists 函数。此外,您还可以使用 curl 函数测试您的 url。

【讨论】:

    猜你喜欢
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 2014-07-15
    • 2012-07-11
    • 2010-11-18
    • 1970-01-01
    • 2016-06-04
    • 2015-09-04
    相关资源
    最近更新 更多