最主要原理是根据:"Content-Type: application/force-download;"和"Content-Disposition: attachment;"来达到目的。
代码如下:
$content_url//下载文件地址,可以是网络地址,也可以是本地物理路径或者虚拟路径
ob_end_clean(); //函数ob_end_clean 会清除缓冲区的内容,并将缓冲区关闭,但不会输出内容。
header("Content-Type: application/force-download;"); //告诉浏览器强制下载
header("Content-Transfer-Encoding: binary");
header("Content-Length: $taille");
header("Content-Disposition: attachment; filename=\"下载后的名字以及后缀\"); //attachment表明不在页面输出打开,直接下载
header("Expires: 0");
header("Cache-control: private");
header("Pragma: no-cache"); //不缓存页面
readfile($content_url);
最佳答案