You are here: Re: File Download NOT open « PHP Programming Language « IT news, forums, messages
Re: File Download NOT open

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация