NYCPHP Meetup

NYPHP.org

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

Jeff Siegel jsiegel1 at optonline.net
Mon Jun 28 12:42:52 EDT 2004


I have a similar piece of code that use where website visitors download 
zipped files...and that works across browsers (and works like a charm).

However, in this case, I'm outputting simple csv...nothing binary.

Jeff

Phillip Powell wrote:

> 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
>>
> 
> 




More information about the talk mailing list