PHP格式的错误 [英] PDF format error with PHP

查看:125
本文介绍了PHP格式的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个带有以下标题的download.php:

I have created a download.php with the following headers:

            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename='.$archivo);
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($ruta));
            readfile($ruta);

但是我看不到文件。我认为这是坏的,但我不知道为什么。这是开始的输出:

But I cannot see the file. I think it's corrupted but I don't know why. This is begining of the output:

%PDF-1.4 %âãÏÓ 3 0 obj <>stream xœ–wTSهϽ7½P’Š"ÐkhRH ½H‘.*1 JÀ"6DTpDQ‘¦2(à€£C‘±"Š…Q±ëDÔqp–Id­ß¼yïÍ›ß÷~kŸ½ÏÝgï}ÖºüƒÂLX €¡Xáçň‹g`ðlàp³³BøF™|ØŒl™ø½º ùû*Ó?ŒÁÿŸ"¹Y"1P˜ŒçòøÙ\É8=Wœ%·Oɘ¶4MÎ0JÎ"Y‚2V"sò,[|ö™e9ó2„<ËsÎâeðäÜ'ã9¾Œ‘`çø¹2¾&cƒtI†@Æoä±|N6(’Ü.æsSdl-c’(2‚-ãyàHÉ_ðÒ/XÌÏËÅÎÌZ.$§ˆ&\S†"‹áÏÏMç‹ÅÌ07#â1Ø™YárfÏüYym²";Ø8980m-m¾(Ô]ü›’÷v–^„îDøÃöW~™ °¦eµÙú‡mi]ëP»ý‡Í`/Š²¾u}qº|^RÄâ,g+«ÜÜ\KŸk)/èïúŸC_|ÏR¾Ýïåaxó"8’t1C^7nfz¦DÄÈÎâpù柇øþuü$¾ˆ/"ED˦L L–µ[Ȉ™B†@øŸšøÃþ¤Ù¹–‰ÚøЖX¥!@~(* {d+Ðï}ÆGùÍ‹Ñ™˜ûÏ‚þ}W¸LþÈ$ŽcGD2¸QÎìšüZ4 E@ê@èÀ¶À¸àA(ˆq`1à‚D €µ "‚­`'¨u 4ƒ6ptcà48.Ë`ÜR0ž€)ð Ì@„…ÈR‡t CȲ…XäCP"%CBH@ë R¨ª†ê¡fè[è(tº C· Qhúz#0 ¦ÁZ°l³`O8Ž„ÁÉð28.‚·À•p|î„O×àX ?§€:¢‹0ÂFB‘x$ !«¤i@Ú¤¹ŠH‘§È[EE1PL"ʅ⢖¡V¡6£ªQP¨>ÔUÔ(j õMFk¢ÍÑÎèt,:‹.FW ›Ðè³èô8úƒ¡cŒ1ŽL&³³³ÓŽ9…ÆŒa¦±X¬:ÖëŠ År°bl1¶ {{{;Ž}ƒ#âtp¶8_\¡8áú"ãEy‹.,ÖXœ¾øøÅ%œ%GÑ.....and so on

如果我用记事本打开相同的pdf:

If I open same pdf with notepad:

%PDF-1.4
%âãÏÓ
3 0 obj
<</Alternate/DeviceRGB/Length 2596/N 3/Filter/FlateDecode>>stream
xœ–wTSهϽ7½P’Š"ÐkhRH
½H‘.*1  JÀ...and so on

有什么问题?当然,与zip或其他格式相同,但是我会使用pdfs。

What's the problem? Of course same happens with zip or other formats, but I will use pdfs.

编辑:我认为问题是我做了is_file($ file)之前头。如果我删除,工程。为什么?¿

谢谢!!!

推荐答案

header('Content-disposition: attachment; filename=yourfile.pdf');
header('Content-type: application/pdf');
readfile('yourfile.pdf');

应该工作...

这篇关于PHP格式的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆