Gamerz Posted July 10, 2009 Share Posted July 10, 2009 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.. Link to comment https://forums.phpfreaks.com/topic/165540-php-replace-space-in-file-names-with-underscore/ Share on other sites More sharing options...
SilverBulletUK Posted July 10, 2009 Share Posted July 10, 2009 <?php echo str_replace(' ', '_', 'Jerrys file with spaces.txt'); #Jerrys_file_with_spaces.txt ?> Link to comment https://forums.phpfreaks.com/topic/165540-php-replace-space-in-file-names-with-underscore/#findComment-873145 Share on other sites More sharing options...
Gamerz Posted July 10, 2009 Author Share Posted July 10, 2009 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... Link to comment https://forums.phpfreaks.com/topic/165540-php-replace-space-in-file-names-with-underscore/#findComment-873153 Share on other sites More sharing options...
SilverBulletUK Posted July 11, 2009 Share Posted July 11, 2009 With respect, it appears it is you who doesn't understand - the code sample provided performs what you requested. On both counts. Link to comment https://forums.phpfreaks.com/topic/165540-php-replace-space-in-file-names-with-underscore/#findComment-873419 Share on other sites More sharing options...
haku Posted July 11, 2009 Share Posted July 11, 2009 Yep. That it will. You just have to change this: 'Jerrys file with spaces.txt' to be a variable that holds the file name. Link to comment https://forums.phpfreaks.com/topic/165540-php-replace-space-in-file-names-with-underscore/#findComment-873439 Share on other sites More sharing options...
npsari Posted July 11, 2009 Share Posted July 11, 2009 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 Link to comment https://forums.phpfreaks.com/topic/165540-php-replace-space-in-file-names-with-underscore/#findComment-873687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.