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>