getimagesize()处理本地路径中的空格?

时间:2014-10-26 05:49:50

标签: php image

我不知道如何让getimagesize()处理本地路径的空间。

对于远程路径:

$path = 'http://example.com/img/1 silver_thumb.JPG';
$new_path = str_replace(" ", "%20", $path)
$temp_array = getimagesize($new_path);
var_dump($temp_array);

会给我一个带图像尺寸的正确数组

但本地路径的等效方法不起作用:

$path = '/Users/snowbound/img/1 silver_thumb.JPG';     // mac path
// $path = '/Users/snowbound/img/1silver_thumb.JPG';     // this works
$new_path = str_replace(" ", "%20", $path)
$temp_array = getimagesize($new_path);
var_dump($temp_array);

$ temp_array是布尔值false。

我还尝试在“引号:

中包围$ path
$new_path = "\"" . $path. "\"";

用反斜杠逃避它:

$new_path = str_replace(" ", "\ ", $path);

两者都不起作用。

当本地路径有空格时,知道如何使用getimagesize()吗?

1 个答案:

答案 0 :(得分:1)

在Ubuntu 9.10上,您无需执行任何操作来更改本地路径。我刚试过这个:

$path = 'gfx/a test image.gif';
$temp_array = getimagesize($path);
var_dump($temp_array);

结果:

array(7) {
[0]=>
int(14)
[1]=>
int(14)
[2]=>
int(1)
[3]=>
string(22) "width="14" height="14""
["bits"]=>
int(2)
["channels"]=>
int(3)
["mime"]=>
string(9) "image/gif"
}

在任何其他Linux版本上应该可以正常工作,如果在BSD / Mac上不起作用会感到惊讶