Forum Moderators: coopster

Message Too Old, No Replies

removing %20 from file names / images

removing %20 from file names / images

         

trimast

12:20 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



Hi,

Part of a system if just set up allows users to upload files and images. Problem is the system is designed to be used by both adults and children, so we are having to make it a user friendly as possible.

Somebody has suggested that kids are likely to upload images with file names such as:

my%20image.gif
my images.gif

i've used the preg_replace php function to remove the whitespace, but am struggling to replace the %20 with an _ .

I'm sure its fairly simple so if anybody could help i'd be most grateful.

Thanks

Rob

omoutop

12:30 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi!
This is the way i do it:

$userfile_name2 = str_replace('%20', '_', $userfile_name);

trimast

12:55 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



I had tried a variant of str_replace, but not as you had it.

Thanks, much appreciated.

Rob

ReveL

12:57 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



%20 and alike are part of urlencoding.

$newname = preg_replace(' ','_',urldecode($name));

omoutop

1:00 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The actual solution is:

$userfile_name2 = str_replace('', '_', $userfile_name);

INSTEAD OF
$userfile_name2 = str_replace('%20', '_', $userfile_name);

in case the second doesnt work....

trimast

2:24 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



actually the '%20' option worked.

With a few alterations to another bit of code it works perfectly now!

Thanks to you all

Rob