2015-09-08 94 views
-1

當我在localhost上執行下面的代碼但pdf未打開。使用php在瀏覽器中打開pdf文件?

將顯示PDF打開失敗的信息。任何問題這個代碼?

<?php 
    //$file = $_POST["image"]; 
    //$filename = $_POST["fname"]; 

    $file = '/home/Desktop/GH-07/hospitalpdf/10004.pdf'; 
    $filename = 'fit.pdf'; 
    header('Content-type: application/pdf'); 
    header('Content-Disposition: inline; filename="' . $filename . '"'); 
    //header('Content-Disposition: inline; filename=''.$filename.'''); 
    header('Content-Transfer-Encoding: binary'); 
    header('Content-Length: ' . filesize($file)); 
    header('Accept-Ranges: bytes'); 
    @readfile($file); 


?> 
+0

使用錯誤報告並找出http://php.net/manual/en/function.error-reporting.php –

+0

謝謝。我會查的 – krishna

回答

0

您嘗試輸出文件(@readfile)的方式是防止打印所有可能的錯誤。 檢查這裏:http://de.php.net/manual/en/language.operators.errorcontrol.php

要麼刪除錯誤控制運算符(@),或者使用不同的方法來打印你的PDF文件,並嘗試擁有控制權的調試階段:

$output = file_get_contents($file); echo $output;