|
Posted by Erwin Moller on 09/13/06 14:23
jerryyang_la1@yahoo.com wrote:
> I have a php page that reads files links from a Database.
> This works well, but when we click on the link the file starts to open.
>
> Is there anyway to force the file to SAVE not open ??
>
> thanks
Yes,
You should send the right headers so the browser knows it should safe the
file.
Here is a piece of code that seems to work for me.
---------------------------
$file_name = 'myexport.csv';
// Create headers for save-as dialog
header('Content-Type: text/comma-separated-values');
//IE need specific header...
if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
{
header('Content-Disposition: inline; filename="'.$file_name.'"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
} else {
header('Content-Disposition: attachment; filename="'.$file_name.'"');
header('Pragma: no-cache');
}
---------------------------
That example was just for a csv file.
You need another content-type for other kind of files.
Maybe reading up here will help a bit:
http://nl2.php.net/manual/en/function.mime-content-type.php
Good luck!
Regards,
Erwin Moller
Navigation:
[Reply to this message]
|