im making currently making my thesis about a record management of our university secretary.. in which all papers inside the office will be scanned and uploaded in the system.. i am using codeigniter..one of the feature in my system is to view the pdf file in other window of the browser. but my problem is, when i click the title. only blank page will be displayed in the other tab.. can you help me solve this one?? here is my code
controller:
function viewMinutesFile(){
if(isset($_GET['id'])){
$id = $_GET['id'];
$file = $this->minutes_model->getFile($id);
$fp= fopen($file->path, "r");
header("Cache-Control: maxage=1");
header("Pragma: public");
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=".$file->filename."");
header("Content-Description: PHP Generated Data");
header("Content-Transfer-Encoding: binary");
header('Content-Length:' .filesize($file->path));
ob_clean();
flush();
while (!feof($fp)){
$buff = fread($fp,1024);
print $buff;
}
exit;
}
}
Run Code Online (Sandbox Code Playgroud)
用于打开文件的代码:这是我的用户单击的语法,以便在新选项卡文件index.php/admin/viewMinutesFile中打开pdf文件?id ="target ="_ tab">
尝试使用静态网址.不需要任何额外的话.
<a href="<?=base_url('any_folder_name/any_file.pdf')?>" target="_blank">Show My Pdf</a>
Run Code Online (Sandbox Code Playgroud)
新的更新
如果你的工作然后从数据库中获取pdf名称并将名称放在视图中
<a href="<?=base_url('index.php/admin/viewMinutesFile/'.$info['doc_id'])?>" target="_blank">Show My Pdf</a>
Run Code Online (Sandbox Code Playgroud)
现在在控制器中
$this->load->helper('download');
if($this->uri->segment(3))
{
$data = file_get_contents('./file_path/'.$this->uri->segment(3));
}
$name = $this->uri->segment(3);
force_download($name, $data);
Run Code Online (Sandbox Code Playgroud)
好吧,你可以添加一个文件链接target="_blank",比如
<a href="<?php echo base_url(). 'your_controller/viewMinutesFile'; ?>" target="_blank">
View Pdf
</a>
Run Code Online (Sandbox Code Playgroud)
并在控制器功能:
function viewMinutesFile(){
....
$file = $this->minutes_model->getFile($id);
$this->output
->set_content_type('application/pdf')
->set_output(file_get_contents($your_pdf_file));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22971 次 |
| 最近记录: |