[SOLVED] header('') Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

[SOLVED] header('') Problem

Post by bluenote »

Hi there,

i have coded an export tool which extracts data from a MySQL DB into XML. In order that the users of this tool don't need to change the extension from .php to .xml or to type in the filename, i have added these headers to the main script:

Code: Select all

<?php
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/force-download');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="test.xml"');
?>
This works quite well. But now i want (in fact, i have to :lol: ) change the filename dynamically in relation to the data exported (i. e. if all articles from 2004 have been selected, the file should be named something like 'artic-2004-all.xml').

Is it possible to insert variables in the header line? Or is there any other trick to do this?? I know that this is maybe a stuuupid question, but it's killing me.

Thanx in advance for help,
- bluenote
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

header('Content-Disposition: attachment; filename="'.$filename.'.xml"');
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

Post by bluenote »

THANX markl999 !!

This works! Prob solved.

- bluenote
Post Reply