我是cakephp和php的新手,我试图在上传后将文件保存到文件夹中。
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.' ) );
}
}
}
答案 0 :(得分:-3)
if ($this->request->is('post') ) {
$filename=$this->request->data('Post.image');
$filename = "app/webroot/img/uploads/".$_FILES[$filename]['name'];
$tempname=$this->request->data('Post.image');
if((move_uploaded_file($_FILES[$tempname']['tmp_name'],$filename)){
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.'));}
}