使用php在浏览器中打开pdf文件?

时间:2015-09-08 13:02:16

标签: php android apache

当我在localhost上执行以下代码但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);


?> 

1 个答案:

答案 0 :(得分:0)

您尝试输出文件(@readfile)的方式是防止打印所有可能的错误。 点击此处:http://de.php.net/manual/en/language.operators.errorcontrol.php

删除错误控制操作符(@),使用不同的方式打印pdf文件,并尝试控制调试阶段:

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

相关问题