PHP下载文件的方法 ajax也是用这种方式 链接跳转就可以了
public function xiazai() { $file_path = __DIR__ . '/../../../Public/qitan.pdf'; $fp = fopen($file_path, "r"); $file_size = filesize($file_path); //下载文件需要用到的头 Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Accept-Length:" . $file_size); Header("Content-Length:" . $file_size); Header("Content-Disposition: attachment; filename=qitan.pdf"); $buffer = 1024; $file_count = 0; //向浏览器返回数据 while (!feof($fp) && $file_count < $file_size) { $file_con = fread($fp, $buffer); $file_count += $buffer; echo $file_con; } fclose($fp); }
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/19012.html