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

Johan Forngren johan at forngren.com
Thu Feb 1 06:58:52 UTC 2007


Try http://api.drupal.org/api/5/function/drupal_set_header

On 2/1/07, Ernst Plüss <ernst.pluess at gmail.com> wrote:
>
> Thanks for your answers guis!
>
> What I did so far:
> 1. generated the content of the excel file and store it in a variable
> 2. sent the appropriate http-header information
> 3. sent the excel file with print $exel_contet;
>
> First this works fine for the user, he gets the download popup and
> stores the file. But the next time the user clicks on a drupal link he
> gets this:
>
> warning: Cannot modify header information - headers already sent by
> (output started at
>
> C:\apachefriends\xampp\htdocs\istl\modules\simplenews\simplenews.module:1729)
> in C:\apachefriends\xampp\htdocs\istl\includes\common.inc on line 269.
>
> I'm sure to not have any spaces sent before my header information is
> sent. But somehow drupal isn't happy that I'm sending header
> informations myself.
>
> This is my code:
>     if ($where && $where_tid) {
>       $query = 'SELECT DISTINCT s.mail, s.name FROM {sn_subscriptions}
> s INNER JOIN {sn_snid_tid} t ON s.snid = t.snid WHERE ('.$where.') AND
> ('.$where_tid.')';
>       $result = db_query($query);
>       while ($mail = db_fetch_object($result)) {
>         $mails[] = $mail;
>       }
>     }
>
>     $data = "Name\tEmail\n";
>     foreach($mails as $entry) {
>         $line = simplenews_clean_value($entry->name);
>         $line .= simplenews_clean_value($entry->mail);
>         $data .= trim($line)."\n";
>     }
>     $data = str_replace("\r","",$data);
>     header("Content-type: application/x-msdownload");
>     header("Content-Disposition: attachment; filename=news_export.xls");
>     header("Pragma: no-cache");
>     header("Expires: 0");
>     print "$data";
>
>
>
> Any ideas?
> TIA Ernst
>



-- 
Regards,
  Johan Forngren

  johan at forngren.com :: http://johan.forngren.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20070201/9cef1946/attachment-0001.htm 


More information about the development mailing list