如何在沒有我的控制器嘗試加載不存在的.ctp文件的情況下渲染。CakePHP 3,如何在沒有CTP的情況下渲染
這是我的代碼:
//without this, I get an error trying to load a non-existent .ctp file. When I include it, the browser does not render the PNG file.
$this->autoRender = false;
//... get avatar code
if (!file_exists($avatarPath))
throw new Exception('Could not find file: '.$avatarPath);
$file = file_get_contents($avatarPath);
header('Content-Type: image/png');
if ($file === false)
throw new Exception('file_get_contents failed on avatarPath');
else
echo $file;
當我使用$this->autoRender = false;
,該header
調用似乎被忽略。有任何想法嗎?
感謝。執行此操作後,我收到一個錯誤:「請求的文件包含'..',不會被讀取。」 - 爲了解決這個問題,我必須先更改目錄,然後再切換回來:( – toast
這是一個安全檢查,以防止目錄遍歷攻擊。 – burzum