عثمان غني
عثمان غني

Reputation: 2708

File is not uploading to folder in cakephp (without plugin)

I am uploading file to a folder in CakePHP. I have written the following code.The name of the file is inserted into database properly but file is not uploaded.

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');
            }
    }

I have uploads folder at location bug/app/tmp/uploads and it is writable.

But after clicking the submit button all the values inserted into database but file is not uploading.

Please Help Thanks

Upvotes: 0

Views: 260

Answers (1)

Vijay Choudhary
Vijay Choudhary

Reputation: 848

Try this

$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);

Upvotes: 2

Related Questions