How do I force files to open in the browser instead of downloading (PDF)?

后端 未结 13 1127
别跟我提以往
别跟我提以往 2020-11-22 04:15

Is there a way to force PDF files to open in the browser when the option \"Display PDF in browser\" is unchecked?

I tried using the embed tag and an iframe, but it o

13条回答
  •  臣服心动
    2020-11-22 05:07

    Oops, there were typing errors in my previous post.

        header("Content-Type: application/force-download");
        header("Content-type: application/pdf");
        header("Content-Disposition: inline; filename=\"".$name."\";");
    

    If you don't want the browser to prompt the user then use "inline" for the third string instead of "attachment". Inline works very well. The PDF display immediately without asking the user to click on Open. I've used "attachment" and this will prompt the user for Open, Save. I've tried to change the browser setting nut it doesn't prevent the prompt.

提交回复
热议问题