Home > php教程 > PHP源码 > PHP实现文件强制下载

PHP实现文件强制下载

PHP中文网
Release: 2016-05-25 17:04:27
Original
1095 people have browsed it

PHP实现文件强制下载

如果你不希望txt  pdf  excel在浏览器上查看的话,强制下载吧


<?php
    $file_dir = "./";   
    $name = "test.txt";
    $file = fopen($file_dir.$name,"r"); 
    Header("Content-type: application/octet-stream");
    Header("Accept-Ranges: bytes");
    Header("Accept-Length: ".filesize($file_dir . $name));
    Header("Content-Disposition: attachment; filename=".$name);
    echo fread($file, filesize($file_dir.$name));
    fclose($file);
?>
Copy after login

以上就是PHP实现文件强制下载的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template