NYCPHP Meetup

NYPHP.org

[nycphp-talk] Proper File Downloads Across Browsers

Hans Zaunere hans at nyphp.org
Wed Jul 9 11:29:37 EDT 2003


Hey all,

I've written a file/report manager for our Intranet, and it entails mostly of presenting a directory listing, some meta data, and then allowing the user to download the file, or if it's a zip, to browse it online.  Things have worked out smashingly, but I ran into some oddities when presenting a file for download.

I currently have something along the lines of:

      header('Content-type: application/x-download');
      header("Content-Disposition: attachment; filename={$meta['filesaveas']}");
      readfile(DATADIR.$meta[FILE]);

This causes both IE and Mozilla to properly present the Save As dialog box, and save the file without munging the extension, etc.  However, I realize that application/x-download isn't a valid MIME type, so it's basically working by default, rather than by design.

I had originally used application/octet-stream for the Content-type, which worked with Mozilla, but IE 6.0 insisted it was a WinZip file and would append .zip to my prepared filename (which is generally .rpt for Crystal Reports).

If anyone has any best-practice ideas for the proper MIME type to use, I'd appreciate it.  To be safe, I'll need to support Netscape 4.7 and IE 5.5 or better versions of either.  I'd like to avoid browser detection if possible, but if someone has a surefire Browser Version => Content-Type mapping, I would toss get_browser() into the mix.


Thanks,

H







More information about the talk mailing list