我正在尝试使这段代码正常工作:
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
]
]
慕工程0101907