/    Sign up×
Community /Pin to ProfileBookmark

Create download

Hi

I have a page where I generate a table with data. I want this data to be available as download (text file for example) without actually creating the file on disk first. I want to have a button for “Download this data”, and when clicked I want to perhaps display a page saying something like “you’re file is being downloaded”.

As I understand it, I can use

[code=php]header(‘Content-Disposition: attachment; filename=”report.txt”‘);
readfile(‘temp_file.txt’);[/code]

But will not everything I send, including my pretty HTML afterwards, be downloaded then?

Thanks
Lubox

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehJul 10.2006 — PHP will send whatever the logic of the script instructs it to send.
Copy linkTweet thisAlerts:
@LuboxauthorJul 10.2006 — Maybe I asked a stupid question, let me try to show what I want:

[code=php]
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=report.txt");

echo "Content of textfile";
[/code]


After the echo, is it possible in any way to "reset" the headers, making it possible to echo html which will not be in the text-file, but displayed in the browser as usual?

Thanks

Lubox

[I]Genius may have its limitations, but stupidity is not thus handicapped.[/I]
Copy linkTweet thisAlerts:
@bokehJul 10.2006 — After the echo, is it possible in any way to "reset" the headers, making it possible to echo html which will not be in the text-file[/QUOTE]No! These must be dealt with in separate requests.
×

Success!

Help @Lubox spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...