我是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