2013-02-14 87 views
0

我試圖在上傳到應用文件夾下的標誌文件夾後回顯圖片。上傳工作正常,但我現在面臨的挑戰是迴應視圖中的圖像。以下是我的上傳功能和視圖代碼上傳後在cakephp中回顯圖片

function uploadFile() { 
$file = $this->data['Logo']['file']; 
if ($file['error'] === UPLOAD_ERR_OK) { 
$id = String::uuid(); 
if (move_uploaded_file($file['tmp_name'], APP.'logos'.DS.$id)) { 
$this->request->data['Logo']['filename'] = $file['name']; 
$this->request->data['Logo']['filesize'] = $file['size']; 
$this->request->data['Logo']['filemime'] = $file['type']; 
return true; 
} 
} 
return false; 
} 

併爲視圖代碼,我使用此代碼。

<?php echo $this->Html->image(APP. 'logos' . DS. $logo['Logo']['filename']); ?> 

感謝您的幫助,您將提供。

回答

2

app folder有一個.htaccess,它不允許直接訪問webroot文件夾之外的任何內容。爲了便於使用,您應該在某處將webroot文件夾內的圖像上傳。

+0

謝謝Danial it works – Mhofhands 2013-02-14 09:53:16