我正在尝试使这段代码正常工作: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 关注
- 109 浏览
添加回答
举报
0/150
提交
取消