Jump to content

Ultra simple


johnsmith153

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/161431-ultra-simple/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/161431-ultra-simple/#findComment-851916
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/161431-ultra-simple/#findComment-851929
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.