我是cakephp和php的新手,我試圖在上傳文件後將文件保存到文件夾中。非法字符串偏移'名稱'[APP Controller PostsController.php,第18行]
public function add() {
if ($this->request->is ('post')) {
$filename = "app/webroot/img/uploads/" . $this->data ['Post'] ['Image'] ['name'];
if ((move_uploaded_file ($this->data ['Post'] ['Image'] ['tmp_name'], $filename))) {
$this->Mathang->create();
if ($this->Post->save ($this->request->data)) {
$this->Session->setFlash (__ ('save images successful.'));
redirect()
$this->redirect ('/posts/upload');
}
} else {
$this->Session->setFlash (__ ('not save images.'));
}
}
}
你可以嘗試'var_dump'-ING $這 - >數據,看看屬性 '名稱' 存在? – EWit 2014-11-22 10:52:40
@Trang Nguyen Quoc,你錯過';'在行尾:'redirect()' – 2014-11-22 11:22:16
你應該在將文件擴展名上傳到web文檔根目錄下的某個地方之前驗證它,否則可以上傳一個'.php'文件。 – Gumbo 2014-11-22 12:06:45