如何檢查瀏覽器中是否打印了某些東西?我試過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