insert a filename in db not array in CakePHP when uploading

I am using CakePHP 2.1 and trying to upload files into server.

I can successfully move the files to specified directory with manually naming a file, but its not taking the name from the file type from view: register.

Database table: users
Id Auto_Increment
username
file_name
Controller : UsersController.php
public function register(){
    if ($this->request->is('post')){
        //   $this->data['User']['resume_file']['tmp_name'] = 'test.php';
        //  The above statement is working good

        if ($this->User->save($this->request->data)){
            $this->Session->setFlash('Message : ' . $this->data['User']['resume_file']['tmp_name']);
            //debug($this->data['User']['resume_file']['tmp_name']);

            // This is giving an error, while inserting
        }
    }
}
View : users/register.php
<?php
    echo $this->Form->create('User', array('type'=>'file'));
    echo $this->Form->input('username');
    echo $this->Form->input('file_name', array('type'=>'file', 'label'=>'Upload document') );
    echo $this->Form->end('Register');
?>
Error : Database error
INSERT INTO `sample_db`.`users` (`file_name`, `created`) VALUES (Array, '2012-06-14 08:10:10')

What i seen is that, while insert into table, Array is inserted thats and error Array to string conversion error in CakePHP now how can i get the value of that input type : file_name in CakePHP

Or else if we can modify the data before saving with the below request statement..

$this->request->data

I tried to change that, with below statement

$this->data['User']['resume_file']['tmp_name'] = 'test.php';

but couldn't its returning same error, any idea...

Answers


Try this:

public function register(){
    if ($this->request->is('post')){
        $filename = $this->request->data['User']['file_name']['tmp_name'];
        $this->data['User']['file_name'] = $filename;

        if ($this->User->save($this->request->data)){
            $this->Session->setFlash('Message : ' . $filename);
        }
    }
}

Need Your Help

how to group xml elements in java by attributes

java xml domparser

I have a requirement for grouping XML elements with same attribute in Java.

Gnuplot CCDF plotting and log-log scale

gnuplot cdf

My data file is a set of sorted single-column: