开发者

trouble with php getimagesize (url encode problems with space)

开发者 https://www.devze.com 2023-02-16 02:30 出处:网络
I use getimagesize to judge an image height and size. Wh开发者_高级运维en a url has space, the getimagesize echo\'s an error. I\'ve tried using urlencode() to transfer all the url address, it still

I use getimagesize to judge an image height and size.

Wh开发者_高级运维en a url has space, the getimagesize echo's an error. I've tried using urlencode() to transfer all the url address, it still returns an error. I noticed that if I just change the space into %20, getimagesize runs ok.

I have no idea why?

I also tired to use $newurl = preg_replace(' ', '%20', $url); It echo'ed :

Warning: preg_replace() [function.preg-replace]: Empty regular expression

So how to preg_replace correctly. And is there a way to transfer the url correctly with getimagesize so that it passes all possible test cases.

Thanks


you should use str_replace(' ', "%20", $url) instead of preg_replace(' ', '%20', $url);


urldecode() is the function you want to use to decode all those characters back after you've converted them before processing the image. Run the string containing the URL through that.


If only the file name contains spaces you can use rawurlencode().

$url = dirname($url) . '/'. rawurlencode(basename($url));


Can you post some example code from when you tried to use urlencode? Also, you don't need to use preg_replace for the last bit, you can simply use str_replace.

0

精彩评论

暂无评论...
验证码 换一张
取 消