0

我正在将文件上传到 CakePHP 中的文件夹。我编写了以下代码。文件名已正确插入数据库,但未上传文件。

function addtickets(){
$this->data['Ticket']['attachment']=date('YmdHis').$this->data['Ticket']['attachment']['name'];
            if ($this->Ticket->save($this->data)){
                $target_path = "bug/app/tmp/uploads/";
                $target_path = $target_path . basename( $_FILES['Ticket']['attachment']['name']); 
                if(move_uploaded_file($_FILES['Ticket']['attachment']['tmp_name'], $target_path)) {
                    echo "The file ".  basename( $_FILES['Ticket']['attachment']['name']). 
                    " has been uploaded";
                    } else{
                    echo "There was an error uploading the file, please try again!";
                }
         $this->Session->setFlash('Ticket created');
} else {
                $this->Session->setFlash('Cannot create a ticket');
            }
    }

我在位置有上传文件夹,bug/app/tmp/uploads它是可写的。

但是在单击提交按钮后,所有值都插入到数据库中,但文件没有上传。

请帮忙谢谢

4

1 回答 1

2

尝试这个

$new_file_location = APP.'tmp'.DS.'uploads'.DS.$this->data['Ticket']["attachment"]['name'];

move_uploaded_file($this->data['Ticket']["attachment"]['tmp_name'], $new_file_location);
于 2013-01-30T07:25:37.320 回答