force to download file
am 17.12.2007 21:13:45 von Hiep Nguyen
------=_NextPart_000_0661_01C840BF.6AE54280
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
hi all,
i have this on top of my php page:
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: inline; filename=3Dexcelfile.xls");
but it is not prompt to save the file instead it opens right in IE.
my question is how do i force the browser prompts to save the file?
thanks
------=_NextPart_000_0661_01C840BF.6AE54280--
Re: force to download file
am 17.12.2007 21:17:34 von Stephen Johnson
IE likes excel files, and wants to open them for you since it is such a
"helpful" application...
If you want to force the download you need to lie to the browser and claim
you are passing a file that it won't know what to do with.
You can try an exe header, but that will likely prompt security warnings
that will bug your users.
--
Stephen Johnson c | eh
The Lone Coder
http://www.thelonecoder.com
continuing the struggle against bad code
http://www.thumbnailresume.com
--
> From: Hiep Nguyen
> Date: Mon, 17 Dec 2007 15:13:45 -0500
> To:
> Subject: [PHP-DB] force to download file
>
> hi all,
>
> i have this on top of my php page:
>
> header("Content-Type: application/vnd.ms-excel");
> header("Content-Disposition: inline; filename=excelfile.xls");
>
> but it is not prompt to save the file instead it opens right in IE.
>
> my question is how do i force the browser prompts to save the file?
>
> thanks
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: force to download file
am 17.12.2007 21:17:48 von parasane
On Dec 17, 2007 3:13 PM, Hiep Nguyen wrote:
> hi all,
>
> i have this on top of my php page:
>
> header("Content-Type: application/vnd.ms-excel");
> header("Content-Disposition: inline; filename=excelfile.xls");
>
> but it is not prompt to save the file instead it opens right in IE.
>
> my question is how do i force the browser prompts to save the file?
>
> thanks
Hiep,
This is a question that should've been asked on the PHP General
list, so I'm reply-all'ing and sending it to the General list for the
archives as well.
Here's a function I use that should help you out.
function force_download($filename,$dir='./') {
if ((isset($file))&&(file_exists($dir.$file))) {
header("Content-type: application/force-download");
header('Content-Disposition: inline; filename="'.$dir.$filename.'"');
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($dir.$filename));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($dir.$filename);
} else {
echo "No file selected";
}
}
?>
--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: force to download file
am 17.12.2007 21:17:48 von parasane
On Dec 17, 2007 3:13 PM, Hiep Nguyen wrote:
> hi all,
>
> i have this on top of my php page:
>
> header("Content-Type: application/vnd.ms-excel");
> header("Content-Disposition: inline; filename=excelfile.xls");
>
> but it is not prompt to save the file instead it opens right in IE.
>
> my question is how do i force the browser prompts to save the file?
>
> thanks
Hiep,
This is a question that should've been asked on the PHP General
list, so I'm reply-all'ing and sending it to the General list for the
archives as well.
Here's a function I use that should help you out.
function force_download($filename,$dir='./') {
if ((isset($file))&&(file_exists($dir.$file))) {
header("Content-type: application/force-download");
header('Content-Disposition: inline; filename="'.$dir.$filename.'"');
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($dir.$filename));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($dir.$filename);
} else {
echo "No file selected";
}
}
?>
--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: force to download file
am 18.12.2007 06:49:10 von Lasitha Alawatta
Hi ,
=0ATry with this header.
=09$export_file =3D "Yo=
urFileName.xls";
=09ob_end_clean();
=09ini_set('zl ib.output_compr=
ession','Off');
header('Pragma: public');
=09header("=
Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
=0A=
=09header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
=09hea=
der('Cache-Control: no-store, no-cache, must-revalidate');
// HTTP/1.1=
header('Cache-Control: pre-check=3D0, post-check=3D0, max-age=3D=
0');
// HTTP/1.1
=09header ("Pragma: no-cache");
=09header("=
Expires: 0");
=09header('Content-Transfer-Encoding: none');
=09he=
ader('Content-Type: application/vnd.ms-excel;');
// This should work f=
or IE & Opera
=09header("Content-type: application/x-msexcel");
/=
/ This should work for the rest
=09header('Content-Disposition: attach=
ment;
filename=3D"'.basename($export_file).'"');
= 0D
=0A=
Regards,
Lasitha
-----Original Message-----
From: Hiep=
Nguyen [mailto:hnguyen@jadesterling.com]
=0ASent: Tuesday, December 1=
8, 2007 12:14 AM
To: php-db@lists.php.net
Subject: [PHP-DB] force=
to download file
hi all,
i have this on top of my ph=
p page:
header("Content-Type: application/vnd.ms-excel");
h=
eader("Content-Disposition: inline; filename=3Dexcelfile.xls");
=
but it is not prompt to save the file instead it opens right in IE.
=0D=
=0Amy question is how do i force the browser prompts to save the file?
=
=0Athanks
DOTW DISCLAIMER:
This e-mail and any attach=
ments are strictly confidential and intended for the addressee only. If you=
are not the named addressee you must not disclose, copy or take
any a=
ction in reliance of this transmission and you should notify us as soon as =
possible. If you have received it in error, please contact the message send=
er immediately.
This e-mail and any attachments are believed to be fre=
e from viruses but it is your responsibility to carry out all necessary vir=
us checks and DOTW accepts no liability
in connection therewith.
=
=0AThis e-mail and all other electronic (including voice) communicati=
ons from the sender's company are for informational purposes only. No such=
communication is intended
by the sender to constitute either an elect=
ronic record or an electronic signature or to constitute any agreement by t=
he sender to conduct a transaction by electronic means.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP-DB] force to download file
am 18.12.2007 10:57:11 von Richard Heyes
>> i have this on top of my php page:
>>
>> header("Content-Type: application/vnd.ms-excel");
>> header("Content-Disposition: inline; filename=excelfile.xls");
>>
>> but it is not prompt to save the file instead it opens right in IE.
>>
>> my question is how do i force the browser prompts to save the file?
header('Content-Disposition: attachment; filename="'.$filename.'"');
?>
That should do the trick, but if not then try adding the Content-Type
header from below.
>
> function force_download($filename,$dir='./') {
> if ((isset($file))&&(file_exists($dir.$file))) {
> header("Content-type: application/force-download");
> header('Content-Disposition: inline; filename="'.$dir.$filename.'"');
> header("Content-Transfer-Encoding: Binary");
> header("Content-length: ".filesize($dir.$filename));
> header('Content-Type: application/octet-stream');
> header('Content-Disposition: attachment; filename="'.$filename.'"');
> readfile($dir.$filename);
> } else {
> echo "No file selected";
> }
> }
> ?>
FYI You have Content-Disposition twice; you only need the second.
--
Richard Heyes
http://www.websupportsolutions.co.uk
Knowledge Base and HelpDesk software
that can cut the cost of online support
** NOW OFFERING FREE ACCOUNTS TO CHARITIES AND NON-PROFITS **
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP-DB] force to download file
am 18.12.2007 10:57:11 von Richard Heyes
>> i have this on top of my php page:
>>
>> header("Content-Type: application/vnd.ms-excel");
>> header("Content-Disposition: inline; filename=excelfile.xls");
>>
>> but it is not prompt to save the file instead it opens right in IE.
>>
>> my question is how do i force the browser prompts to save the file?
header('Content-Disposition: attachment; filename="'.$filename.'"');
?>
That should do the trick, but if not then try adding the Content-Type
header from below.
>
> function force_download($filename,$dir='./') {
> if ((isset($file))&&(file_exists($dir.$file))) {
> header("Content-type: application/force-download");
> header('Content-Disposition: inline; filename="'.$dir.$filename.'"');
> header("Content-Transfer-Encoding: Binary");
> header("Content-length: ".filesize($dir.$filename));
> header('Content-Type: application/octet-stream');
> header('Content-Disposition: attachment; filename="'.$filename.'"');
> readfile($dir.$filename);
> } else {
> echo "No file selected";
> }
> }
> ?>
FYI You have Content-Disposition twice; you only need the second.
--
Richard Heyes
http://www.websupportsolutions.co.uk
Knowledge Base and HelpDesk software
that can cut the cost of online support
** NOW OFFERING FREE ACCOUNTS TO CHARITIES AND NON-PROFITS **
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php