Headers that makes the browser download the file.

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Headers that makes the browser download the file.

Post by Takuma »

I'm making a database backuper and I want for the user to be able to download the sql query file afterwards. Which headers do I send in this case to the browser?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

what do you send? The result of an export like

Code: Select all

CREATE TABLE `whatever` (
....
) TYPE=MyISAM;
....
INSERT INTO whatever VALUES("1", "2");
INSERT INTO whatever VALUES("2", "3");
....
if so I suggest CXII. Zlib Compression Functions and the mime-type is application/x-gzip or application/zip
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

So how do I tell browser to download to the zgip file?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

really depends on the average file size.
If bandwidth and/or storage is not the problem you can try it with

Code: Select all

<?php
$filename = 'export.sql'; // e.g.
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$filename);
readfile($filename);?>
first....
Post Reply