Jump to content

PHP - Replace space in file name's with underscore..


Gamerz

Recommended Posts

Hello,

I have a file uploader....

 

I want to automatically replace any file that has been uploaded that has a space with an underscore (_) at anytime.

 

Example: If Jerry uploaded a file called jerry file.txt, I want to be able to automatically replace it with jerry_file.txt...

 

Any possible way of doing that? And if so, where would I place it at? My uploader is just like any other php uploader...an upload form, and an upload processing script....do i place it at the upload form or second script? thanks..

No, you don't understand..

 

I don't want to modify a specific file only. I want to, like...anytime someone uploads a file with a space, it would be automatically replaced with an underscore...and anyone who doesnt have a space like jerry.txt, then just leave the file alone...

 

Lets assume the Image field is called Image1 ...

 

 

$original_image_name = basename( $_FILES['Image1']['name']);
$new_image_name = str_replace(' ', '_', $original_image_name);

 

If you are asking about the code which uploads the image to your server, then, thats another topic  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.