我正在嘗試使這段代碼正常工作:if ($this->request->is(['patch', 'post', 'put'])){ $nameImg = $this->request->getData()['imagem']['name']; $imgTmp = $this->request->getData()['imagem']['tmp_name']; $destination = "files\user\\".$user_id."\\".$nameImg; if(move_uploaded_file($imgTmp,WWW_ROOT . $destination)){ $this->Flash->success(__('Success!')); } }但每次我嘗試運行它時,圖像都會保存在我的 webroot 目錄中,而不是我指定的 $destination 路徑上,所有目錄都設置為 777 并且 move_uploaded_file 返回 true,我可以做些什么來使其保存在指定路徑上?這是$this->request->getData();調試輸出:[ 'imagem' => [ 'tmp_name' => '/tmp/phpTrcN6K', 'error' => (int) 0, 'name' => 'icone1.png', 'type' => 'image/png', 'size' => (int) 15778 ]]
1 回答

慕工程0101907
TA貢獻1887條經驗 獲得超5個贊
嘗試在路徑中使用目錄分隔符(DS):
if ($this->request->is(['patch', 'post', 'put'])){
$nameImg = $this->request->getData('imagem.name');
$imgTmp = $this->request->getData('imagem.tmp_name');
$destination = WWW_ROOT . 'files' . DS . 'user' . DS . $user_id . DS . $nameImg;
if(move_uploaded_file($imgTmp, $destination)){
$this->Flash->success(__('Success!'));
}
}
- 1 回答
- 0 關注
- 137 瀏覽
添加回答
舉報
0/150
提交
取消