强制在php中下载文件 [英] Force file download in php

查看:81
本文介绍了强制在php中下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个简单的文件管理器,用户可以在其中下载任何类型的文件,例如pdf,word或gif文件.我希望所有人都下载文件,而不是在浏览器中查看文件.上载的文件名存储在数据库中.

I have built a simple file manager where users can download any type of file such as pdf, word or gif files. I want all of them to download file rather than view it in browsers. The uploaded filenames are stored in database.

推荐答案

<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');

// The PDF source is in original.pdf
readfile('original.pdf');
?> 

http://php.net/manual/en/function.header.php

这篇关于强制在php中下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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