php 简单的文件下载

Controller.php:

 
 
$file_size=filesize('文件路径');
$fp=fopen('文件路径','r');    //只读模式打开
Header("Content-type:application/octet-stream");
Header("Accept-Ranges:bytes");
Header("Accept-Length:".$file_size);
Header("Content-Disposition:attachment;filename=demo.docx");
$buff=1024;
$file_count=0;
while(!feof($fp) && $file_count<$file_size){
    $file_con=fread($fp,$buff);
    $file_count+=$buff;
    echo $file_con;
    ////输出到浏览器
}
fclose($fp);

 
 
show.html
<input type="button" id="down" />
<script>
    document.getElementById("down").onclick=function()
    {
        window.location.href='test.php';
    }
</script>

 
 

猜你喜欢

转载自blog.csdn.net/j393819650/article/details/68061017