3
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;

        }
    }

ファイルを開くためのコード: これは、pdf ファイルが新しいタブ ファイル index.php/admin/viewMinutesFile? で開かれるように、ユーザーがクリックする私の構文です。id="ターゲット="_tab">

4

6 に答える 6

5

target="_blank"さて、次のようにファイルへのリンクを追加できます

<a href="<?php echo base_url(). 'your_controller/viewMinutesFile'; ?>" target="_blank">
    View Pdf
</a>

そしてコントローラー関数で:

function viewMinutesFile(){
    ....
    $file = $this->minutes_model->getFile($id);
    $this->output
           ->set_content_type('application/pdf')
           ->set_output(file_get_contents($your_pdf_file));
}
于 2013-08-12T04:54:21.960 に答える
1

これに従ってください。

<?php echo form_open_multipart('your_controller/your_function','target="_blank"') ;?>
    //other input fields
<?php form_close();?>
于 2014-12-17T13:26:23.660 に答える
1

次のタブで簡単に開くことができるコードに問題はありません。他のページと同様に、ヘッダーの説明を変更する必要があるだけで、ブラウザーで pdf リーダー アドオンが利用可能であることを確認してください。ダウンロード。

于 2013-08-12T05:03:55.697 に答える