我有這個page,應該是一首歌曲的下載。下載在Firefox對我的作品,但在Chrome和Safari沒有happens..here是我的代碼文件傳輸代碼在我的PHP中是否正確?
public function download() {
if (isset($this->request->get['order_download_id'])) {
$order_download_id = $this->request->get['order_download_id'];
} else {
$order_download_id = 0;
}
$download_info = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_download od LEFT JOIN `" . DB_PREFIX . "order` o ON (od.order_id = o.order_id) WHERE o.customer_id = '" . (int)$this->customer->getId(). "' AND o.order_status_id > '0' AND o.order_status_id = '" . (int)$this->config->get('config_download_status') . "' AND od.order_download_id = '" . (int)$order_download_id . "'");
if ($download_info->row) {
$file = DIR_DOWNLOAD . $download_info->row['filename'];
$mask = basename($download_info->row['mask']);
$mime = 'application/octet-stream';
$encoding = 'binary';
if (!headers_sent()) {
if (file_exists($file)) {
header('Pragma: public');
header('Expires: 0');
header('Content-Description: File Transfer');
header('Content-Type: ' . $mime);
header('Content-Transfer-Encoding: ' . $encoding);
header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
header('Content-Length: ' . filesize($file));
$file = readfile($file, 'rb');
print($file);
} else {
exit('Error: Could not find file ' . $file . '!');
}
} else {
exit('Error: Headers already sent out!');
}
}
}
我已經嘗試了各種不同的東西來得到這個工作,但沒有在兩個瀏覽器發生..任何想法或幫助將不勝感激...
我不認爲你想打印readfile的返回值 - 你已經發送了內容的長度,這將是意想不到的(加上它會破壞接收端的文件)。 –
如果您刪除底部的重定向文件,您會得到一個文件嗎?我對IE沒有足夠的瞭解,但它可能只是讀取頭並在處理響應主體之前遵循重定向流。 – Candide
到目前爲止沒有我沒有收到文件 – Trace