Home > Backend Development > PHP Tutorial > readfile下载文件添ob_clean作用

readfile下载文件添ob_clean作用

WBOY
Release: 2016-06-13 12:05:39
Original
1113 people have browsed it

readfile下载文件加ob_clean作用
手册中readfile例子

$file = '12.jpg';<br /><br />if(file_exists($file)){<br />	<br />	header('Content-Description: File Transfer');<br />	header('Content-type: application/octet-stream');<br />	header('Content-Disposition: attachment; filename=' . basename($file));<br />	header('Content-Transfer-Encoding: binary');<br />	header('Expires: 0');<br />	header('Cache-control: must-revalidate');<br />	header('Pragma: public');<br />	header('Content-Length: ' . filesize($file));<br />	ob_clean();<br />	flush();<br />	readfile($file);<br />	exit();<br />}
Copy after login

在这里加ob_clean和flush有什么作用?不加也能下载,加不加有什么区别
------解决方案--------------------
如果说 ob_clean(); 清除缓冲区,用的还有点道理的话
那么 flush(); 推出输出缓冲区,就没有道理了
因为无论如何,输出缓冲区中的内容都要被输出的

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