我正在使用这个代码来通过PHP提供下载文件:
$file='file.pdf'; $filepath="/path-to-download-folder/$file"; if(!file_exists($filepath)){ header('HTTP/1.1 404 Not Found'); exit; }elseif(!is_file($filepath) or !is_readable($filepath)){ header('HTTP/1.1 403 Forbidden'); exit; }else{ header('Cache-Control: no-store, no-cache, must-revalidate'); header('Content-Type: '.mime_content_type($filepath)); header('Content-Length: '.filesize($filepath)); header('Content-Disposition: attachment; filename="'.$file.'"'); set_time_limit(0); // Big files/slow connections may result in incomplete downloads readfile($filepath); exit; }
但是有些人正在收到一个损坏的PDF文件。
例如: http : //mlkshk.com/r/8FGS
在Nginx中我有这样的:
gzip on; gzip_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
我的问题是:如何设置它不是gzip PDF文件? 也许这是问题…
谢谢。
使用您当前的configuration,您不是在浏览PDF文件,但是您可以使用Firebug或Google PageSpeed等工具进行检查
http://wiki.nginx.org/NginxHttpGzipModule#gzip_types
gzip_types syntax: gzip_types mime-type [mime-type ...] default: gzip_types text/html context: http, server, location Enables compression for additional MIME-types besides "text/html". "text/html" is always compressed.
但是,你有没有试过使用x-sendfile?