www.webdeveloper.com
Results 1 to 8 of 8

Thread: File Extension Work Around for FireFox

  1. #1
    Join Date
    Feb 2011
    Location
    Indiana
    Posts
    2

    Exclamation File Extension Work Around for FireFox

    I'm working on a PHP based site with download-able files, which come zipped on download. IE, Chrome and Safari have no issue with recognizing the file extension. Firefox, on the other hand, leaves off the file type. It's easy enough to just add .zip to the end of the file name, but is there a hack/fix/work-around that can be put in the code (or some other way) to force the extension to attached to the file?

  2. #2
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    PHP Code:
    <?php
    $foo 
    pack(x);

    for(
    $i 0$i 25$i++) {
      
    $foo .= $foo;
    }


    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=decompression.bomb.zip");
    header("Pragma: no-cache");
    header("Expires: 0");

    echo 
    $foo;

    ?>
    I think you need to recompress it a few hundred times recursively in a ZipArchive() to get my script to work as intended. Firefox thinks its a zip and saves it as a .zip

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,355
    Quote Originally Posted by paradoxica View Post
    I'm working on a PHP based site with download-able files, which come zipped on download. IE, Chrome and Safari have no issue with recognizing the file extension. Firefox, on the other hand, leaves off the file type. It's easy enough to just add .zip to the end of the file name, but is there a hack/fix/work-around that can be put in the code (or some other way) to force the extension to attached to the file?
    I've downloaded plenty of zip files over the years with FF and never ran into this issue, so I'm not really sure what to suggest without knowing the specifics of what you're doing in your code. Eval's header() suggestions should deal with it OK, setting the attachment stuff and content-type.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Feb 2011
    Location
    Indiana
    Posts
    2
    Quote Originally Posted by NogDog View Post
    I've downloaded plenty of zip files over the years with FF and never ran into this issue, so I'm not really sure what to suggest without knowing the specifics of what you're doing in your code. Eval's header() suggestions should deal with it OK, setting the attachment stuff and content-type.
    I too have never had an issue with downloading files from Firefox, until this site. It was developed by an outside vendor before I came on board. My co-worker and I are trying to sort through the mess. (Believe me; it's fairly sloppy and somewhat confusing.)

    Thanks for the suggestion.

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,355
    Hmm...I wonder if it is setting a Content-Type header() indicating a Zip archive (probably "application/zip") and then sending a file name without a ".zip" suffix? It might be worth checking the HTTP response headers to see if it gives any clues along that line.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Feb 2011
    Posts
    9
    I had a similar problem today, only with a different file type. Adding quotes around the filename seems to have fixed it, but for some reason IE replaces spaces with underscores, though that's not a problem.

    Try this:
    PHP Code:
    <?php
    $foo 
    pack(x);

    for(
    $i 0$i 25$i++) {
      
    $foo .= $foo;
    }

    $file 'decompression.bomb.zip';
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.$file.'"');
    header('Pragma: no-cache');
    header('Expires: 0');

    echo 
    $foo;
    ?>

  7. #7
    Join Date
    Feb 2011
    Posts
    9
    Hmm... Seems I can't edit my post =/
    Anyways, I've just made a post on my site that goes into more detail and includes the problem snippet I had to fix - may be worth taking a look

  8. #8
    Join Date
    Jul 2010
    Location
    /ramdisk/
    Posts
    865
    Oh lol... my decompression bomb did not work. However, it seems the only way to delete that file on wunderp7 is to shred it.

    as annoying if not better the null byte strikes again
    Last edited by eval(BadCode); 02-17-2011 at 04:36 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles