我们正在尝试显示PDF File
来自Live Server(PHP Verion 5.2)的文件,该文件未正确显示...而不是文件bytecode
。
如果尝试从本地服务器(PHP版本5.4)显示,则显示相同的文件。
我们尝试了以下操作以从服务器显示PDF(其中显示ByteCode):
header("Content-type: application/pdf");
header("Content-Length: " . filesize($url_path)); // '$url_path' variable is fullpath to PDF file
readfile($url_path) or die("File not found ");
输出字节码:
%PDF-1.5 2 0 obj << >> endobj 3 0 obj << /Type /Page /Parent 1 0 R /MediaBox [0 0 598 834] /Contents 4 0 R /Resources << /XObject << /img0 5 0 R >> /ProcSet [ /PDF /Text /ImageC] /Font 2 0 R >> /Annots 6 0 R >> endobj 4 0 obj << /Filter /FlateDecode /Length 61 >> stream x
如果我们尝试使用下面的行显示,则可以正常工作。
echo "<script type='text/javascript'> window.location.href = '".$url_path."'; </script>";
我们已经尝试过更改.htaccess代码,如下所示:
(1) RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+).pdf$ /cgi-bin/pdf.php?file=$1 [L,NC,QSA]
(2) RewriteEngine On
RewriteCond %{REQUEST_URI} \.(pdf)$ [NC]
RewriteRule ^ /viewpdf.php?request_url=%{REQUEST_URI} [L]
还是行不通..
终于得到了解决方案:
在声明时,header
我们应注意不要在其之前声明echo
或print_r
应声明。
如果我们导入文件中require(..)
或include(..)
或require_once(..)
也不应包含任何echo
声明..否则,所有header
后声明将被忽略..
简而言之:在标头语句上方,不应编写任何echo语句,否则所有标头声明都将被忽略。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句