处理具有空格的文件名

My script here works fine:

image protection in codeigniter

However it displays a broken image if my filename has a space, so say it is "obama 1.jpg".

To try and resolve this problem, I have used http://php.net/manual/en/function.escapeshellarg.php

And replaced all the white spaces in the img_id with "%"s.

But I have had no luck. I cannot strip the white spaces out, so will have to make due with the structure of the string.

Thanks for your help.

When you call the image just use

echo urlencode($image_name);

That should fix it!

If you are using the filenames in URLs try replacing the space with %20 so "obama%201.jpg"