tags:

views:

161

answers:

4

Hello, please I need hep with the following.

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

ie pics name is: aa 22.jpg

If uploaded this way it does not show it because of the space between aa and 22. What it the way to get rid of the space or replace it with % when uploaded?

Many many thanks. Francesco

+2  A: 

Can't you just...

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

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

Langdon
I am using an upload class which would be too tricky to change. I was thinking at something more directly involved with upload file.
francesco
So when you use the class, does it fail when you upload a file that contains a space? If it fails, you'll need to fix the class itself... if it succeeds and returns you the filename with the space, simply use the rename() function to remove the spaces...
Langdon
A: 

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.

joukokar
+1  A: 

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);

Sarfraz
A: 

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

joe