Forum Moderators: phranque

Message Too Old, No Replies

.htaccess to force files to be viewed in browser?

The reverse of forcing files to download

         

jrissler

7:52 pm on Aug 27, 2007 (gmt 0)

10+ Year Member



I've had some problems with my websites, where a PHP page will occasionally open with a Save As dialog, rather than being viewed in the browser. I have seen some .htaccess tricks to force a file to download with a save as dialog, but is there any way to use .htaccess to force a file to be viewed in the browser?

phranque

11:22 pm on Aug 27, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you can suggest browser behavior but it is difficult if not impossible to force browser behavior.
if you provide a Content-type: header that is supported by the browser and possibly depending on the Content-disposition: header, the browser will try to view the document.
otherwise, most browsers will ask you to save as or select an external viewer.
neither will prevent you from right clicking a link or a page to save as a download.
it is also often possible and usually unpreventable to find the document/file in temporary cache and move/rename it to something useful...