getimagesize()函数不适用于某些图像

时间:2016-06-28 05:17:00

标签: php getimagesize

某些图片的

getimagesize()函数返回FALSE

示例: enter image description here

$path1 = getcwd().'/images/communities/29/eagle-ridge-26.jpg';
$vals_arr1 = getimagesize($path1);

$path2 = 'http://homematrix.oskyserver.com/images/communities/29/
                                               eagle-ridge-26.jpg';
$vals_arr2 = getimagesize($path2);

在这两种情况下,它都返回FALSE,我已经搜索过,但还没有找到一个好的解决方案。

1 个答案:

答案 0 :(得分:0)

它的工作:

您必须提供绝对路径:

例如:

$path1 = getcwd().'/images/logo.jpg';
$vals_arr1 = getimagesize($path1);
echo "<pre>";var_dump($vals_arr1);echo "</pre>";

$path2 = __DIR__.DIRECTORY_SEPARATOR.'images/logo.jpg';
$vals_arr2 = getimagesize($path2);
echo "<pre>";var_dump($vals_arr2);echo "</pre>";

结果:

array(7) {
  [0]=>
  int(288)
  [1]=>
  int(70)
  [2]=>
  int(2)
  [3]=>
  string(23) "width="288" height="70""
  ["bits"]=>
  int(8)
  ["channels"]=>
  int(3)
  ["mime"]=>
  string(10) "image/jpeg"
}
array(7) {
  [0]=>
  int(288)
  [1]=>
  int(70)
  [2]=>
  int(2)
  [3]=>
  string(23) "width="288" height="70""
  ["bits"]=>
  int(8)
  ["channels"]=>
  int(3)
  ["mime"]=>
  string(10) "image/jpeg"
}