0

Hi People;

I've got issue in uploading image in cake php.

Thing is that, I have a form, where i have input type="file".
I need to upload a file in a directory and save its path in database.

In "view" its like...

<tr><td>
<?php    echo $this->Form->input('field', array(
    'type' => 'file',           
    'label' => 'Please Upload Signature of Sales Manager'
    ));
?>
</td></tr>    

and in the "Controller" its like

$dir = WWW_ROOT.'documents';
$slas= '\\';                    

$filenamez= $this->data['Invoice']['field']['name'];

$dir=$dir.$slas.$filenamez;
echo $dir;
move_uploaded_file($this->data['Invoice']['field']['tmp_name'],$dir);  

I'm getting this error....

SQL Query: UPDATE `acm`.`invoices` SET `last_modified` = '2013-06-24 10:10:16', `last_mod_by` = 'Admin User', `invoice_number` = '1306190003', `invoice_date` = '2013-06-19', `invoice_total` = 316.00, `sales_manager` = 'Lucius Fox', `status` = 'Part Paid', `public_notes` = 'We appreciate your business.\r\nRefer the above order in accordance with the prices, terms and other specifications listed above.', `private_notes` = '', `field` = Array WHERE `acm`.`invoices`.`id` = '3' 

How to insert the uploaded file path in database?

Thanks

5
Contributors
7
Replies
46
Views
4 Years
Discussion Span
Last Post by mandeep_2
0

Thanx for the reply sir, but I don't want to store the file itself in db.... I want to upload the file in a directory and save its path in the column of database table.... So that I could retreive it later.

I liked your name though..... RadhaKrishna....... Sounds so divine....

0

My file is getting uploaded in proper directory... only issue is that I'm not able to store the path name in a column of database table.

Its returning that value as an array.... its failinmg somewhere here

fieldpath = Array WHERE acm.invoices.id = '3'

I tried implode and serialize too... to make it a string... but it still throws this error..
Column not found: 1054 Unknown column 'Array' in 'field list'

0

Ok... I had placed the code after save() function.... It should have been before that...

Its working now... It should return a string (the path of the directory where the uploaded image is stored). It was returning Array.

Thanx All.

Error was this:

Database Error Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'field list'

This link was helpful though.

http://stackoverflow.com/questions/16262194/file-upload-in-cakephp-2-3

0

i suggest to store only the name of the image in databse.When you want to display it you can give the folder path + image name(that comes from databse). this is better than storing whole path in database.

0

your view should be -- for example

<?php echo $this->FORM->create('post',array('action'=>'add','enctype' => 'multipart/form-data')); 
echo $this->FORM->input('title',array('required'=>'required'));
echo $this->FORM->input('body',array('required'=>'required'));
echo $this->Form->file('Document.submittedfile'); 
echo $this->FORM->end('add post');

and action where ur saving data to db -- ex

$file = $this->request->data['Document']['submittedfile'];
$file_n = $this->data['Document']['submittedfile']['name'];/*name of file*/

$alldata = array_merge($this->request->data['post'],$array1);
move_uploaded_file($this->data['Document']['submittedfile']['tmp_name'],$_SERVER['DOCUMENT_ROOT'] . '/cakephp/app/webroot/files/' . $this->data['Document']['submittedfile']['name']); 

$this->post->save($alldata);
0

hello dear in view .ctp
<?php echo $this->FORM->create('post',array('action'=>'add','enctype' => 'multipart/form-data'));
what is mean of "post" here my means is post is a controller or table name of database
$file = $this->request->data['Document']['submittedfile'];
what measn of "Document" ,"submittedfile" here
what mean of the following
action where ur saving data to db
my means folder name or controllername or table name or anything else...please reply me..

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.