0
當我使用下面的代碼下載文件時,它在IE,Firefox中可以正常工作,但通過Chrome,您可以看到佈局和視圖被髮送回控制檯中的瀏覽器。狀態已設置取消,整條線以紅色突出顯示。該文件已下載確定。Zend下載文件Chrome
退出後;還有我曾嘗試過各種頭opions,但無濟於事
if ($request->isPost()) {
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout()->disableLayout();
$file_fullpath = "C:/eclipse-php/workspace/Dartfire/uploads/data/logo.jpg";
$mtype = '';
// magic_mime module installed?
if (function_exists('mime_content_type')) {
$mtype = mime_content_type($file_fullpath);
}
// fileinfo module installed?
else if (function_exists('finfo_file')) {
$finfo = finfo_open(FILEINFO_MIME); // return mime type
$mtype = finfo_file($finfo, $file_fullpath);
finfo_close($finfo);
}
$size = filesize($file_fullpath);
header('Content-Type: image/jpg');
header('Content-Disposition: attachment; filename="logo.jpg"');
readfile($file_fullpath);
exit;
//header("Content-type: application/octet-stream");
/*
$this->getResponse()
->setHeader('Content-Description', 'File Transfer', true)
->setHeader('Content-Type', $mtype, true) // change to application/pdf
->setHeader('Content-Disposition', "attachment; filename={$document->getFilename()}", true)
->setHeader('Content-length', $size, true)
->setHeader('Content-Transfer-Encoding', 'binary', true)
->setHeader("Content-type", "application/octet-stream")
->setHeader('Cache-control', 'private')
->appendBody(readfile($file_fullpath));
//->sendHeaders();
//$this->getResponse()->sendResponse();
//Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
}
在readFILE()之後的頭部調用都被註釋掉 - 它們只是我嘗試過的東西的一個指示。 – Leopard
明白,但是當你試用它們時,你實際上是否將readfile()部分放在最後? – maurits
是的 - 謝謝,但readfile是最後一個 – Leopard