johnsmith153 Posted June 8, 2009 Share Posted June 8, 2009 I have this: if(file_exists($fileurl)) { header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Transfer-Encoding: binary"); readfile($fileurl); } Which offers user to open or save a file How do I do so it opens the file automatically in the same window? Quote Link to comment https://forums.phpfreaks.com/topic/161431-ultra-simple/ Share on other sites More sharing options...
gijew Posted June 8, 2009 Share Posted June 8, 2009 If it's a PDF, image, html or anything a browser can understand just output the file to the browser or set the header's to the proper content type. Quote Link to comment https://forums.phpfreaks.com/topic/161431-ultra-simple/#findComment-851907 Share on other sites More sharing options...
johnsmith153 Posted June 8, 2009 Author Share Posted June 8, 2009 How would I do this? Please bear in mind that all files (which are pdf) must be stored outside public_html. Basically I want the code I posted above, but an automated way where it just "presses open" rather than offer user open / save choice. Quote Link to comment https://forums.phpfreaks.com/topic/161431-ultra-simple/#findComment-851909 Share on other sites More sharing options...
gijew Posted June 8, 2009 Share Posted June 8, 2009 Well, the user MUST have a PDF reader of some type installed on their system or the browser will output a "Save As" regardless. I did something where you could "preview" a file once that involved using the database ID to query, check if it existed, made sure it was in an allowed list of file types, and output it to the browser directly. Without all of the security warnings one could add here, you can output a PDF file directly to the browser but it MUST be in a web accessible directory. So the URL would look something like http://www.example.com/pdfs/test.pdf Quote Link to comment https://forums.phpfreaks.com/topic/161431-ultra-simple/#findComment-851916 Share on other sites More sharing options...
johnsmith153 Posted June 8, 2009 Author Share Posted June 8, 2009 It doesn't have to be in a web accessible directory. I have solved my problem fully. Answer: 1. replace the word "attachment" with "other" 2. add in: header("Content-type: application/force-download"); You can access a pdf that is stored outside of the public_html and it will do exactly as I wanted it to. Quote Link to comment https://forums.phpfreaks.com/topic/161431-ultra-simple/#findComment-851929 Share on other sites More sharing options...
.josh Posted June 8, 2009 Share Posted June 8, 2009 umm...the point of being inside public_html vs. outside public_html is that one is accessible to the public and the other is not. If this file is somehow accessible directly even though it is outside of public_html, then the chmod on the folder is set to allow it. Quote Link to comment https://forums.phpfreaks.com/topic/161431-ultra-simple/#findComment-851931 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.