我正在将文件上传到 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
它是可写的。
但是在单击提交按钮后,所有值都插入到数据库中,但文件没有上传。
请帮忙谢谢