我试图在broswer窗口中显示pdf并获取一些文本作为回复。请告诉我我在做错误的地方。这是我的代码:
$filepath = 'ssh2.sftp://<ftpuser>:<ftp password>@<ftphost>/scratch/user1/opt/portal/7.5/custom/apps/cus_transfer_invoice/BA10000892/B1-13370/Invoice_BA10000892_B1-13370_189.pdf';
header('Content-type: application/pdf');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($filepath));
header('Accept-Ranges: bytes');
readfile($filepath);
我得到的输出是这样的:
JVBERi0xLjQKJeLjz9MKMiAwIG9iago8PC9MZW5ndGggNTIvRmlsdGVyL0ZsYXRlRGVjb2RlPj5zdHJlYW0KeJwr5HIK4TI2UzA3M9Azs1AISeFyDeEK5CpUMFQwAEIImZyroB + RZqjgkq8QyAUACHQKjQplbmRzdHJlYW0KZW5kb2JqCjQgMCBvYmoKPDwvVHlwZS9QYWdlL01lZGlhQm94WzAgMCA2MTIgNzk2LjY4XS9SZXNvdXJjZXM8PC9Qcm9jU2V0IFsvUERGIC9UZXh0IC9JbWFnZUIgL0ltYWdlQyAvSW1hZ2VJXS9YT2JqZWN0PDwvWGYxIDEgMCBSPj4 + Pi9Db250ZW50cyAyIDAgUi9QYXJlbnQgMyAwIFI + PgplbmRvYmoKNiAwIG9iago8PC9MZW5ndGggNTIvRmlsdGVyL0ZsYXRlRGVjb2RlPj5zdHJlYW0KeJwr5HIK4TI2UzA3M9Azs1AISeFyDeEK5CpUMFQwAEIImZyroB + RZqTgkq8QyAUACHsKjgplbmRzdHJlYW0KZW5kb2JqCjcgMCBvYmoKPDwvVHlwZS9QYWdlL01lZGlhQm94WzAgMCA2MTIgNzk2LjY4XS9SZXNvdXJjZXM8PC9Qcm9jU2V0IFsvUERGIC9UZXh0IC9JbWFnZUIgL0ltYWdlQyAvSW1hZ2VJXS9YT2JqZWN0PDwvWGYyIDUgMCBSPj4 + Pi9Db250ZW50cyA2IDAgUi9QYXJlbnQgMyAwIFI + PgplbmRvYmoKOSAwIG9iago8PC9MZW5ndGggNDkvRmlsdGVyL0ZsYXRlRGVjb2RlPj5zdHJlYW0KeJwr5HIK4TI2UzA3NVMISeFyDeEK5CpUMFQwAEIImZyroB + RZqzgkq8QyAUA60cJ + AplbmRzdHJlYW0KZW5kb2JqCjEwIDAgb2JqCjw8L1R5cGUvUGFnZS9NZWRpYUJveFswIDAg&#34;
答案 0 :(得分:0)
删除Content-Length标头。这几乎肯定是你的问题。参见例如Sending correct file size with PHP download script 如果它没有那个标题,你可以尝试找出标题错误的原因,或者只是发送没有内容长度(基本上可以正常工作)
有关如果没有Content-Length标题,会发生什么情况的更多信息,请参阅What are the consequences of not including a content-length header in a server response?。