<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_42389"> <div class="blockcode"> <div id="code_s5y"><ol> <li> <li><?php <li>/**<li>* header与readfile函数应用举例<li>* 下载文件 判断权限<li>* edit bbs.it-home.org<li>*/ <li>$file = get_file_address();// 文件的真实地址(支持url,不过不建议用url)<li> <li>if (file_exists($file)) <li>{<li>header('Content-Description: File Transfer');<li>header('Content-Type: application/octet-stream');<li>header('Content-Disposition: attachment; filename='.basename($file));<li>header('Content-Transfer-Encoding: binary');<li>header('Expires: 0');<li>header('Cache-Control: must-revalidate, post-check=0, pre-check=0');<li>header('Pragma: public');<li>header('Content-Length: ' . filesize($file));<li>ob_clean(); //注意此函数的调用,清空但不关闭输出缓存,否则下载的文件头两个字符会是0a <li>flush();<li>readfile($file); // 输出文件内容 <li>}<li>?></li> </ol></div> <em onclick="copycode($('code_s5y'));">复制代码</em> </div> </td></tr></table> <div id="comment_42389" class="cm"> </div> <div id="post_rate_div_42389"></div> <br><br>