开发者

PHP upload pics with space

I have an upload pictures form. I need to make sure that pictures which contain spaces in the name are replaced with something else, my guess is %.

ie the picture's name is: aa 22.jpg

If uploade开发者_Python百科d this way it does not show because of the space between aa and 22. What is the way to get rid of the space or replace it with % when uploaded?


rather than replacing file name with empty string, it is good idea to replace it with an underscore to maintain the readability and actual name of the file in its sense:

$file = str_replace(' ', '_', $file);


Can't you just...

$filename = str_replace(' ', '', $filename);

Are you using some upload handler that you don't have control over?


you can use trim($picture), but dont know where to put it, finding out my self right now


If the file uploads correctly but just doesn't show up in the browser, you might try aa%2022.jpg, since %20 is used instead of spaces in URLs (and iirc some browser won't realize this automatically).

But since it's ugly, you might prefer replacing spaces with something else. You can use str_replace function to achieve this.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜