如何让PHP在新标签中打开PDF文件? [英] How do I get php to open a pdf file in a new tab?

查看:204
本文介绍了如何让PHP在新标签中打开PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白我一直在阅读的文件。谁能在这里解释如何做到这一点?

我有一个HTML链接进入函数showFile()。有两个获取,一个ID,这是文件名,和一个扩展名,文件的扩展名(只有扩展名将是pdf,jpg和gif)我使用codeigniter framwework btw。



我读了关于标题的东西,但是当我试图下载文件时。任何帮助将不胜感激。



到目前为止的功能---------

  public function showFile(){
$ fileId = $ this-> input-> get('id');
$ fileExt = $ this-> input-> get('ext');

$ b $ / code>


解决方案

这在HTML中:

 < a href =downloadfile.php?filesrc = blah.pdftarget = _new> 
点击此处下载blah.pdf< / a>

当然,href必须是 echo ed in PHP。

 < a href =downloadfile.php?filesrc =<?php echo $ filepath?> ; TARGET = _new> ...< / a> 

哦,downloadfile.php只有一个头('。 ..'); 重定向到文件。


I don't understand the documentation I've been reading. Can anyone here explain how to do this?

I have a HTML link that goes to a function showFile(). There are two gets, an id, which is the file name, and an ext, the extension of the file.(Only extensions will be pdf, jpg, and gif) I'm using codeigniter framwework btw.

I read stuff about headers but when i tried that it just downloaded the file. Any help would be appreciated.

Function so far ---------

 public function showFile () {
    $fileId = $this->input->get('id');
    $fileExt = $this->input->get('ext');

}

解决方案

Something like this in HTML:

<a href="downloadfile.php?filesrc=blah.pdf" target=_new>
    Click here to download blah.pdf</a>

Where of course the href has to be echoed in PHP.

<a href="downloadfile.php?filesrc=<?php echo $filepath ?>" target=_new> ... </a>

Oh, and the downloadfile.php will simply have a header('...'); redirect to the file.

这篇关于如何让PHP在新标签中打开PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆