Rad'Val
Rad'Val

Reputation: 9231

PHP: imagecreatefromjpeg($url) doesn't work if $url contains spaces?

I use a script to get an image from another server and store it in the db, the problem is that when the url has a space in it, the function grabs nothing.

I tried to encode the url and to simply replace all spaces with %20 but with no success.

I'm running out of options, if any of you could give me some ideas would be great!

Thanks!

$thumb=imagecreatefromjpeg(http://www.dummysite.ca/imageone.jpg); //->WORKS
$thumb=imagecreatefromjpeg(http://www.dummysite.ca/image one.jpg); //->DOESN'T WORK

EDIT: more info: I'm running a CentOS machine, php 5.2.17

EDIT: found the answer, replacing spaces with %20 actually WORKS but I was foolish and only replace it before the imagecreatefromjpeg call, it turns out getimagesize needs it as well

Upvotes: 2

Views: 4098

Answers (2)

Rad'Val
Rad'Val

Reputation: 9231

So for those who will have a similar problem

replacing spaces with %20 actually WORKS but I was foolish and only replace it before the imagecreatefromjpeg call, it turns out getimagesize needs it as well

Upvotes: 5

Syntax Error
Syntax Error

Reputation: 4527

I would do everything in my power to keep spaces out of filenames. At whatever point the file enters your server it should be renamed to something with underscores. Personally For file uploads I rename every file to a combination of timestamp and the uploader's ip address. Grabbing from another server could use the same logic. If you need to save the original filename just save it as a text string associated with the DB entry.

Upvotes: 1

Related Questions