0
我是CakePHP的新手,嘗試上傳文件,move_uploaded_file
總是返回false
。這裏是我的代碼:CakePHP move_uploaded_file返回false
編輯:第一行是什麼是錯的
// This line was wrong, should be done after uploading.
$this->request->data['Post']['image'] = $this->request->data['Post']['image']['name']
if($this->Post->save($this->request->data)) {
$filename = basename($this->request->data['Post']['image']['name']);
$filePath = WWW_ROOT . DS . 'files' . DS . $filename;
if(move_uploaded_file(
$this->request->data['Post']['image']['tmp_name'],
$filePath
))
$this->Session->setFlash(__('Your post has been saved'));
else
$this->Session->setFlash(__('Your post has been saved, but image failed'));
}
爲什麼不工作?
看到這個http://stackoverflow.com/a/20989968/1239506它可能會幫助你 –