有一朋友需打开Web服务器(nginx)中pdf格式文件实现自动预览--缺省为下载文件,于是网上查阅了些资料,发现是一个名为Content-Disposition
的HTTP头部在控制:
nginx 服务器
以Nginx
服务器为例:
server { listen 8080; server_name _; root /usr/share/nginx/html; location ~* \.(pdf|txt|log)$ { add_header Content-Disposition inline; #add_header Content-Disposition attachment; } }
inline: 自动预览动作
attachment: 下载动作
Apache 服务器
<FilesMatch "\.(?i:pdf)$"> ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch>
预览
经过测试 Chrome、Firefox 皆正常
注意要点
文件名尽量不使用中文
参考引用
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://sg.hqyman.cn/post/9545.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
休息一下~~