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

PHP实现文件强制下载

PHP中文网
PHP中文网Original
2016-05-25 17:04:271052browse

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);
?>

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

Statement:
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