Daniellez
10-12-2009, 06:47 PM
Hi,
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?
$targetFile = str_replace(' ','_',$targetPath) . $_FILES['Filedata']['name'];
:P
Daniellez
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.
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.
Daniellez
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! :)