Jump to content

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

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.