NYCPHP Meetup

NYPHP.org

[nycphp-talk] Header issue...force download

Phillip Powell phillip.powell at adnet-sys.com
Mon Jun 28 10:21:21 EDT 2004


This works for me in Firefox, plain Mozilla, IE, Konqueror and 
Netscape.  Unsure about Opera.

Phil

class DownloadGenerator {

    /**
     * Full File Path
     *
     * @access private
     * @var mixed $fullFilePath
     */
    var $fullFilePath;

    /**
     * Constructor
     *
     * @access public
     */
    function DownloadGenerator($fullFilePath) {            // CONSTRUCTOR
        $this->fullFilePath = $fullFilePath;
    }

    /**
     * Generate header information to cause a forced download
     *
     * @access public
     * @param mixed $fullFilePath (optional)
     */
    function &generateForceDownloadHeaders($fullFilePath = '') {        
    // STATIC VOID METHOD
        $file = ($this->fullFilePath) ? $this->fullFilePath : $fullFilePath;
        if (is_file($file)) {
         $filesize = @filesize($file);
         header('Content-Disposition: attachment; filename="' . 
substr($file, strrpos($file, '/') + 1, strlen($file)) . '"');
         header("Content-Length: $filesize");
         header('Content-Type: application/octet-stream');
         header('Content-Transfer-Encoding: binary');
         header('Pragma: no-cache');
         header('Expires: 0');
         @readfile($file);
         @set_time_limit(600);
        }
    }

}


Jeff Siegel wrote:

> Didn't seem to have any effect.
>
> Jeff
>
> Brian Pang wrote:
>
>> I think you need to set the Content-Type to
>> application/octet-stream
>>
>>
>>
>>
>>> The snippet of code below works fine with IE and not Firebird. In 
>>> IE, you get prompted to save the file and it displays a filename of 
>>> 'author.csv.' In Firebird, it displays a filename of 
>>> 'author.csv.php'. It's that "php" extension that doesn't belong there.
>>>
>>> Header('Content-Type: text/csv\n',true);
>>> Header('Content-Disposition: attachment; filename="author.csv"');
>>> Header('Pragma: no-cache',true);
>>> Header('Expires: 0',true);
>>>
>>> Jeff
>>>
>>>
>>>
>>> _______________________________________________
>>> talk mailing list
>>> talk at lists.nyphp.org
>>> http://lists.nyphp.org/mailman/listinfo/talk
>>>
>>>
>>
>>
>>
>> _______________________________________________
>> talk mailing list
>> talk at lists.nyphp.org
>> http://lists.nyphp.org/mailman/listinfo/talk
>>
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>


-- 
---------------------------------------------------------------------------------
Phil Powell
Multimedia Programmer
BPX Technologies, Inc.
#: (703) 709-7218 x107 
Fax: (703) 709-7219

	




More information about the talk mailing list