Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 05-26-2010, 10:40 AM   #1
Member (7 bit)
 
Join Date: Dec 2005
Posts: 87
cakePHP and file uploads

When I create a form without a file upload field in cakephp, I am able to update the database. But when I add file upload fields, the database does not update. Here is my code:

controller:
PHP Code:
class CarsController extends AppController {

    var 
$name 'Cars';
    var 
$helpers=array('Html','Form');
                                    
    
    
//new car function for creating a new car record
    
function register(){
        if(!empty(
$this->data)){
            if(
$this->Car->save($this->data,false)){
                
$this->Session->setFlash('Car added');
            }
        }
    }

model
PHP Code:
class Car extends AppModel {

    var 
$name 'Car';

view
PHP Code:
<?php echo $form->create('Car', array('action' => 'register''type' => 'file'));?>

<?php
    
echo $form->input('stockno');
    echo 
$form->input('vin');
    echo 
$form->input('year');
    echo 
$form->input('make');
    echo 
$form->input('model');
    echo 
$form->input('type');
    echo 
$form->input('color');
    echo 
$form->input('engine');
    echo 
$form->input('transmission');
    echo 
$form->input('condition');
    echo 
$form->input('retailprice');
    echo 
$form->input('mileage');
    echo 
$form->input('warranty');
    echo 
$form->input('description');
    echo 
$form->file('front');
?>

<?php echo $form->end('Register');?>
Thanks.
hartken is offline   Reply With Quote
Old 05-26-2010, 11:42 AM   #2
Member (7 bit)
 
Join Date: Dec 2005
Posts: 87
I figured it out:

The file field returns as an array instead of a single value, causing save to fail. What I needed was a line of code setting $this->data['Car']['front'] to a single value, in this case, the tmp_name of the uploaded image.
hartken is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:45 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2