views:

134

answers:

1

When I choose an image and push upload, I get this error in my controller: Notice (8): Undefined index: File [APP/controllers/garage_car_images_controller.php, line 22]

I've also noticed that the $form->create line shown below does NOT generate form code in the inspected html. This is VERY weird.

Any ideas how to fix this? Thanks!

My view code:

<div class="title_plate">
    <h1 id="title_plate_header">add image</h1>
</div>
<div id="overlay_content">
<?php
    echo $form->create('GarageCarImage', array('controller' => 'garage_car_images','action' => 'add', 'type' => 'file'));
    echo $form->file('File');
    echo $form->hidden('garage_car_id', array('value' => $this->params['pass'][0]));
    echo "<br><br>";
    echo "Make this image the default? " . $form->input('default', array('type' => 'select', 'label' => false, 'options' => array('0' => 'No', '1' => 'Yes')));
    echo "<br>";
    echo $form->submit('Upload');
    echo $form->end();
?>
</div>

My controller code:

if (!empty($this->data) &&
             is_uploaded_file($this->data['GarageCarImage']['File']['tmp_name'])) {
            $fileData = fread(fopen($this->data['GarageCarImage']['File']['tmp_name'], "r"),
                                     $this->data['GarageCarImage']['File']['size']);

            $this->data['GarageCarImage']['type'] = $this->data['GarageCarImage']['File']['type'];
            $this->data['GarageCarImage']['user_id'] = $this->Auth->user('id');
            $this->GarageCarImage->save($this->data);
}
+1  A: 

Are you sure it doesn't generate the form code? If it didn't, I don't think you would even be able to try and submit a form. I believe submitting the form occurs because you seem to issue a request for /garageCarImages/index -- to me, that says that the form is getting generated properly.

If indeed that is the case, you should just change the value of the first parameter to the name of the controller that you want the code to execute in. For me, typically, I use an Attachment controller to do this, so I would put:

echo $form->create( 'Attachment', array(...) );

Your situation will depend on where the code is located to process the upload. Most likely it's the ImageController (guessing here...), but I'm not sure without knowing more details of your system.

Travis Leleu