知道文件的路径怎么实现浏览器端的下载(文件是源文件)

WBOY
Release: 2016-06-13 11:48:35
Original
1545 people have browsed it

知道文件的路径如何实现浏览器端的下载(文件是源文件)

本帖最后由 u013293559 于 2014-02-10 12:11:05 编辑 知道文件的路径如何实现浏览器端的下载(文件是源文件)求求大神给支招......................
------解决方案--------------------
header('Content-Disposition:attachment;filename=test.php');
readfile('a.php');//目标文件
------解决方案--------------------
<br /><?php<br />$file_dir = '';//定义文件路径<br />$file_name = '';//定义文件名字<br />$file = fopen($file_dir . $file_name,"r"); // 打开文件<br />Header("Content-type: application/octet-stream");<br />Header("Accept-Ranges: bytes");<br />Header("Accept-Length: ".filesize($file_dir . $file_name));<br />Header("Content-Disposition: attachment; filename=" . $file_name);<br />// 输出文件内容<br />echo fread($file,filesize($file_dir . $file_name));<br />fclose($file);<br />exit();<br />?><br />
Copy after login
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!