Force the browser to show the Save File dialog box

This is much needed when you want to force the web browser to show the Save File dialog box. Generally the web browser opens the file which can be read by it.

It all depends on the header which is being sent from the web server to the client browser. By default, the browser can open the images i.e. .gif, j.pg, .png & some other file as well like .swf (for FF especially).

This is how it can be implemented with Content-disposition. For example I want to force to save the .swf file.

The PHP code will be:

<?phpheader('Content-disposition: attachment; filename=filename.swf');header('Content-type:application/x-shockwave-flash');readfile('pathoffile/filename.swf');exit;?>

Related Posts

View Comments to “Force the browser to show the Save File dialog box”

  1. Dharmesh 16 May 2010 at 4:46 pm #

    Useful post…
    Here is the .Net way of doing it: http://forums.asp.net/p/936625/1110987.aspx


Leave a Reply

blog comments powered by Disqus