[development] How do I send a file to the user?

Konstantin Käfer kkaefer at gmail.com
Thu Feb 1 14:45:45 UTC 2007


The magic lines are:

// Start download process
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: text/plain; charset=utf-8");

but actually, they should be drupal_set_header() instead of header()  
calls.

On 01.02.2007, at 03:14, Peter Wolanin wrote:

> Having been sorting this out myself recently, i'll also add that you
> can look at the locale module for an example of this in core, and
> importexport module (and probably several others) for contrib examples
> that export CSV or similar files.
>
> http://api.drupal.org/api/5/function/_locale_export_po
>
> -Peter
>
> -----
> From: Moshe Weitzman <weitzman at tejasa.com>
> To: development at drupal.org
> Date: Wed, 31 Jan 2007 17:26:10 -0500
> Subject: Re: [development] How do I send a file to the user?
> Ernst Plüss wrote:
>> Hi
>>
>> I want to do the following: The users fills out a form and depending
>> on that data an excel export is generated. The user should be  
>> prompted
>> to store/open the file.
>>
>> The code to create the excel data is working fine.
>>
>> But I don't know how to do the file sending stuff?
>> Is hook_file_download the right way to go? If yes, after I have the
>> excel file content stored in a variable how does it get to the
>> implementation of hook_file_download?
>>
>> TIA
>> Ernst
>
> no, thats not the right function. you just need to send the right http
> headers and then print out your excel data. see http://us2.php.net/ 
> header.
> you can use that function directly. no benefit to going through  
> drupal here.



Konstantin Käfer – http://kkaefer.com/




More information about the development mailing list