SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cross platform file downloads?

    When storing files in a MySQL database and allowing users to download them, how would you go about making it work cross platform? I mean, the mime types are different for MAC and PC's and there are SOO many different types of files so you can't really do a mime type conversion or something.. there's gotta be an easier way.

  2. #2
    SitePoint Addict launchcode's Avatar
    Join Date
    Dec 2004
    Location
    Bristol, UK
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A mime type is a mime type, it shouldn't make any difference what platform you're sending it to. image/gif is, well.. a gif for Mac and PC browsers. Besides, if you're forcing a file for download you most likely only need to send one content-type anyway: application/octetstream:

    PHP Code:
    @ob_end_clean();
    @
    ini_set('zlib.output_compression''Off');
            
    header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
    header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
    header('Content-Transfer-Encoding: none');
    header('Content-Type: application/octetstream');    //    IE and Opera
    header('Content-Type: application/octet-stream');    //    All other browsers
    header('Content-Transfer-Encoding: Binary');
    header("Content-Length: $filesize");
    header('Content-Disposition: attachment; filename="' $name '"');
    header("Pragma: public");    //    Stop old IEs saving the download script by mistake
    readfile($file);
    exit; 
    Richard Davey

    Launchcode
    PHP Security Guide. Think your scripts are secure? Think again.

  3. #3
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what are the first two lines for?

  4. #4
    SitePoint Addict launchcode's Avatar
    Join Date
    Dec 2004
    Location
    Bristol, UK
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The ones saying "no cache" ??

    They're to tell the browser not to cache the download.
    Richard Davey

    Launchcode
    PHP Security Guide. Think your scripts are secure? Think again.

  5. #5
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no the:

    @ob_end_clean();
    @
    ini_set('zlib.output_compression', 'Off');

  6. #6
    SitePoint Addict launchcode's Avatar
    Join Date
    Dec 2004
    Location
    Bristol, UK
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Disables output buffering and gzip compression (if set).
    Richard Davey

    Launchcode
    PHP Security Guide. Think your scripts are secure? Think again.

  7. #7
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    In laymen's terms it means that the buffer will get rid of any previous data so it doesn't muckup the file you will be feeding for download.
    Wayne Luke
    ------------



Bookmarks

Posting Permissions

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