View Full Version : Resolved Replaces spaces with underscores in upload form...

10-12-2009, 06:47 PM

I currently have the following:

$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

How can this be modified so that spaces in the filename are replaced with an underscore?

10-12-2009, 07:08 PM
$targetFile = str_replace(' ','_',$targetPath) . $_FILES['Filedata']['name'];


10-12-2009, 07:12 PM
Hi, I need to keep the function that replaces the slashes. Perhaps I should have asked "how do I merge the two?"

Or can that be added below? Unfortunately, I can't try it until later this evening.

10-12-2009, 07:25 PM
various ways

easy/lazy way:

$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

$targetFile = str_replace(' ','_',$targetPath) . $_FILES['Filedata']['name'];

edit: do you perhaps mean

$targetFile = str_replace('//','/',$targetPath . $_FILES['Filedata']['name']);

$targetFile = str_replace(' ','_',$targetPath . $_FILES['Filedata']['name']);

instead? don't think php will like the original.

10-12-2009, 07:47 PM
Update: The issue manifested itself when you attempted to download a file with spaces in the filename. After a bit of research however, I found another way. Instead of patching this in the upload process, I made the following changes in the download code:

I changed this:

header("Content-Disposition: attachment; filename=$filename");

To this:

header("Content-Disposition: attachment; filename=\"".$filename."\";" );

I found the fix by viewing the code here (http://elouai.com/force-download.php). I'm not sure why/how adding the quotes works but it does! :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum