1
我想用cakephp在瀏覽器中打開pdf。我將文件保存在webroot/files文件夾中。我知道如何使用直接下載的媒體。但是如何直接在瀏覽器中打開pdf?打開瀏覽器中的webroot的pdf文件cakephp
我想用cakephp在瀏覽器中打開pdf。我將文件保存在webroot/files文件夾中。我知道如何使用直接下載的媒體。但是如何直接在瀏覽器中打開pdf?打開瀏覽器中的webroot的pdf文件cakephp
由於每MediaView書頁,只需設置autoRender
到false
和設置您的控制器命名download
到false
一個視圖變量。同時請確保指定mimeType
,因爲大多數瀏覽器將強制下載未知的MIME類型。
實施例:
function download() {
$this->view = 'Media';
$this->autoRender = false; // Disable auto-render.
$params = array(
'download' => false, // Don't force download.
'id' => 'example.docx',
'name' => 'example',
'extension' => 'docx',
'mimeType' => array('docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'), // extends internal list of mimeTypes
'path' => APP . 'files' . DS
);
$this->set($params);
}