如何检查浏览器中是否打印了某些东西?我试过headers_sent但它的头...... 如果没有印我想下载一个文件:PHP - 检查浏览器中是否有东西被打印
public function download() {
$file = null;
$line = null;
if(headers_sent($file, $line)) {
/* generic exception... change that... */
throw new Exception('Headers was sent before in file ' . $file . ', line #' . $line);
}
header('Content-Description: File Transfer');
header('Content-Type: ' . $this->mime);
header('Content-Disposition: attachment; filename=' . $this->name);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $this->size);
readfile($this->path);
谢谢。
headers_sent是你需要的 – 2010-10-13 14:17:30
你的代码应该按原样工作。如果您输出了任何东西(假设您没有启用输出缓冲),'headers_sent'将返回true,因为您第一次执行PHP会为您发送适当的标头。 – meagar 2010-10-13 14:21:42
headers_sent不起作用:<?php echo'hi'; echo headers_sent(); //没有输出,所以它是假的??> – thomas 2010-10-13 15:01:11