4

I have files that i upload to the website that might contain spaces such as:

    file name 1.wav

It displays normally when uploaded, however when trying to download the file from Chrome and Firefox i get the following results:

  Chrome downloaded: file name 1.wav (perfect)
  firefox downloaded: file (bad) 

name 1.wav was removed from name. Is there any specific functionality in PHP that will fix this problem in firefox?

CODE:

   <?= str_replace(array("'",'"'), array("&#39;","&quot;"), stripslashes($sFileTitle)) ?>', '<?=$f['fileExtension']?>'

This is what shows up when i inspect the element on anchor tag where file should be downloaded:

  <a title="file name 1.wav" fileid="254" class="docLink">file name 1.wav</a>

i use JQuery to redirect to the correct path.

FIX:

Adding urlencode($file) fixed it but arose a new problem. Now file with name

    file name 1.wav

turns into when downloading:

    file+name+1.wav

is it possible to replace + with space once downloading? urldecode didnt work

Solution:

if someone else having same problem here is how i fixed it:

instead of urlencode/decode i just did this:

 '"' . stripslashes($file) . '"'

and it fixed it

4
  • 3
    In your html put urlencode('file name 1.wav');
    – Glavić
    Oct 2, 2012 at 16:05
  • Firefox has no problems with spaces in filenames. Post some code.
    – lanzz
    Oct 2, 2012 at 16:07
  • header("Content-Disposition: attachment; filename=\"$filename\"");
    – FirmView
    Oct 2, 2012 at 16:11
  • 1
    header('Content-Disposition: attachment; filename="Your file name with spaces.wav"');
    – DaveRandom
    Oct 2, 2012 at 16:11

1 Answer 1

3
<?php
      header("Content-Disposition: attachment; filename=\"$filename\"");
?>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.