[PHP-DB] Re: [PHP] Re: [PHP-DB] force to download file

2007-12-18 Thread 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?


?php
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 Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] force to download file

2007-12-17 Thread Hiep Nguyen
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

Re: [PHP-DB] force to download file

2007-12-17 Thread 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 [EMAIL PROTECTED]
 Date: Mon, 17 Dec 2007 15:13:45 -0500
 To: php-db@lists.php.net
 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: [PHP-DB] force to download file

2007-12-17 Thread Daniel Brown
On Dec 17, 2007 3:13 PM, Hiep Nguyen [EMAIL PROTECTED] 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: [PHP-DB] force to download file

2007-12-17 Thread Lasitha Alawatta
Hi , 
Try with this header.


$export_file = YourFileName.xls;
ob_end_clean();
ini_set('zlib.output_compression','Off');

header('Pragma: public');
header(Expires: Mon, 26 Jul 1997 05:00:00 GMT);
// Date in the past 
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
// HTTP/1.1 
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
// HTTP/1.1
header (Pragma: no-cache);
header(Expires: 0);
header('Content-Transfer-Encoding: none');
header('Content-Type: application/vnd.ms-excel;');
// This should work for IE  Opera
header(Content-type: application/x-msexcel);
// This should work for the rest
header('Content-Disposition: attachment;
filename='.basename($export_file).'');



Regards,
Lasitha

-Original Message-
From: Hiep Nguyen [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 18, 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 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
DOTW DISCLAIMER:

This e-mail and any attachments are strictly confidential and intended for the 
addressee only. If you are not the named addressee you must not disclose, copy 
or take
any action 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 sender 
immediately.
This e-mail and any attachments are believed to be free from viruses but it is 
your responsibility to carry out all necessary virus checks and DOTW accepts no 
liability
in connection therewith. 

This e-mail and all other electronic (including voice) communications from the 
sender's company are for informational purposes only.  No such communication is 
intended
by the sender to constitute either an electronic record or an electronic 
signature or to constitute any agreement by the 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