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...