简体   繁体   English

如何在不下载文件的情况下在codeigniter的根文件夹中打开pdf文件?

[英]How to open a pdf located in a root folder in codeigniter without downloading the file?

I am a newbie in codeigniter. 我是Codeigniter的新手。 I am working on a site that can upload and view a PDF file. 我在一个可以上载和查看PDF文件的网站上工作。 I've already succeeded on the upload. 我已经成功上传了。

The problem is, whenever I want to view the uploaded file in the browser, it is automatically downloading. 问题是,每当我要在浏览器中查看上载的文件时,它都会自动下载。 I want to view the PDF file in the browser. 我想在浏览器中查看PDF文件。 how can i do it? 我该怎么做?

here is the code in my VIEW 这是我的视图中的代码

<?php
            echo '<table class  = "table table-striped">';
            echo '<tr>';
            echo '<th class="table_head">Filename</th>';
            echo '<th class="table_head">Department</th>';
            echo '<th class="table_head">Uploaded by</th>';
            echo '<th class="table_head"></th>';
            echo '</tr>';

        if(isset($tbl_uploaded) && is_array($tbl_uploaded) && count($tbl_uploaded) > 0)
        {
            foreach($tbl_uploaded as $uploaded)
            {
                echo '<tr>';
                echo '<td>'. $uploaded->name .'</td>';
                echo '<td>'. $uploaded->department .'</td>';
                echo '<td>'. $uploaded->uploader .'</td>';
                echo '<td><a href="'. base_url().'uploads/'.$uploaded->name .'" target="_new">View</a></td>';
                echo '</tr>';
            }
        }
        echo '</table>';
    ?>

thanks in advance guys 在此先感谢大家

您必须更改浏览器设置。如果您使用的是firefox,只需转到打开菜单,然后选择选项->应用程序,然后选择可移植文档格式(pdf)操作以在firefox中设置预览。

you can try this one, I am using this code to generate a letter from my database, I am also using a codeigniter. 您可以尝试一下,我正在使用此代码从数据库中生成一封信,我也在使用一个Codeigniter。

function createPDF()

{
$data['']= $this->input->post("");
$this->load->library('mpdf');
$this->load->model('');
$query = $this->'your_model'->'model_name'($data);


    if($query!=null)
    {
$hello .=' Insert your letter here
<p>' .$data->something. '</p> //fetch something from your database';

$mpdf=new mPDF('ISO-8859-1','letter', 10, 'Arial', 15, 15, 16, 16, 9, 9, 'P');
$stylesheet = file_get_contents(base_url().'css/pdf.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->SetHTMLHeader('<img src="'.base_url().'css/edrsletter.jpg"></img>');
$mpdf->WriteHTML($hello);
$mpdf->SetFooter(' Sample PDF template  - {PAGENO}');
$mpdf->Output();
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM