Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2002

    MIME Headers in PHP for Downloads

    Hi, guys I've got some headers that allow people to download straight from my page when they visit it which is fine, except I would like people to see the File Name and Type when downloading so its not some unknown file :p

    Current Mime Headers read something like this:
    PHP Code:
    header "Content-Type: application/zip; name=$file");
    Header "Content-Length: ".filesize($file).")");
    Header "Content-Disposition: attachment; filename='".$file); 
    Any idea which MIME headers, will get me the file name that I so very seek

  2. #2
    Join Date
    Jul 2002
    First off, use basename($file) on the last header() call. I'd also add

    header("Content-Transfer-Encoding: binary");
    and header("Pragma: public");
    C#/C++/TCL/Python/PHP developer.
    mark at mark org il

  3. #3
    Join Date
    May 2004
    Lansing, MI, USA
    In our applications... I use...

    PHP Code:
                    header('Cache-control: must-revalidate');
    header('Expires: 0'); // set expiration time
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Accept-Ranges: bytes');
    header('Content-Length: ' $tmp->filesize);
    header('Content-Transfer-Encoding: binary');
    header('Content-Disposition: inline; filename="' $tmp->filename '"');
    Header('Content-type: ' $tmp->filetype); 
    Jacob - WebOnce Technologies - 30 Day 100% Satisfaction Guarantee - Over 5 Years Going Strong!
    Website Hosting, PHP4&5, RoR, MySQL 5.0, Reseller Hosting, Development, and Designs
    Powered By JAM - Professional Website Development - PHP, MySQL, JavaScript, AJAX - Projects Small & Large

  4. #4
    Join Date
    Aug 2002
    Okay, I cleaned it up and added a bit so it reads like:

    PHP Code:
    Header ("Content-Type: application/zip; name=$file");
    Header ("Content-Description: Download of $file");
    Header ("Content-Length: $filesize");
    Header ("Content-Transfer-Encoding: binary");
    Header ("Content-Disposition: attachment; filename=\"$filename\""); 
    This currently shows everything correctly with the exception of the actual FILE NAME and FILE TYPE. I know have the file location showing properly instead of IP

    Does anyone know which MIME type displays the filename? If its the Filename part in Content-Disposition what part of my MIME type is wrong?


  5. #5
    Which MIME type? Mime-type is used to determine the type of the file you send.

    In the last header you're sending (Content-Disposition), the filename part determines what name the file will have when user saves it on his/hers computer.

Posting Permissions

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