使用此PHP代码在新选项卡中打开pdf(Use this php code to open a pdf in a new tab)

编程入门 行业动态 更新时间:2024-10-09 15:24:54
使用此PHP代码在新选项卡中打开pdf(Use this php code to open a pdf in a new tab)

我已经设法使用下面的代码片段,在浏览器中打开pdf。而不是在同一页面打开,我希望它在新的浏览器选项卡中打开。

我没有使用标签。 这段代码调用了许多动作,最后它应该显示pdf。 它工作正常,但我希望它在一个新的选项卡中打开。

这可能吗? 如果可以的话,请向我解释如何这样做。

我使用Magento(EE 12.02)应用程序及其在PHP 5.3上。

$file = $pdf_file_path; $filename = $file_name; header('Content-type: application/pdf'); header('Content-Disposition: inline; filename="' . $filename . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($file)); header('Accept-Ranges: bytes'); @readfile($file);

I have managed to use the below snippet of code, to open a pdf in a browser.Instead of opening in the same page, I would like it to open in a new browser tab.

I am not using an tag. This piece of code invokes a number of actions and at the end it is supposed to display the pdf. It works fine, but i would like it to open in a new tab.

Is this possible? and if so could you please explain to me how to do so.

Im using a Magento (EE 12.02) application and its on php 5.3.

$file = $pdf_file_path; $filename = $file_name; header('Content-type: application/pdf'); header('Content-Disposition: inline; filename="' . $filename . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($file)); header('Accept-Ranges: bytes'); @readfile($file);

最满意答案

你不能从那个请求那里做到这一点。

但是您可以通过在标签中添加target =“_ blank”来在新的浏览器窗口中打开链接,然后浏览器通常会使用新标签。

You can't do that from that request.

But you can open the link in a new browser window by adding target="_blank" to your a tag, then browsers usually will use a new tab.

更多推荐

本文发布于:2023-07-30 16:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338817.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项卡   代码   pdf   PHP   open

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!