I'm trying to add the ability to upload files on an existing add
method within a controller, but no matter which method I use to try
and upload files I get an "undefined index" error on the name of the
field within the view and I cannot understand why.

I thought it may have been a problem with the components I was trying,
but after stripping back to a simple bit of code found here (http://
www.davidgolding.net/cakephp/using-the-file-functions-in-cakephp.html)
- I am still getting the error.

Code looks like this:

// Controller:

                        if ($this->data['Tip']['image']) {

                                $file = new File($this->data['Tip']['image']);
                                $ext = $file->ext();

                                if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 
'gif' && $ext !=
'png') {
                                $this->Session->setFlash('You may only upload 
image files.');
                                $this->render();
                                } else {
                                $date = $this->data['Tip']['created'];
                                $filename = 
$date['year'].'-'.$date['month'].'-'.$date['day'].'-
post-image.'.$ext;

                                $data = $file->read();
                                $file->close();

                                $file = new 
File(WWW_ROOT.'/img/'.$filename,true);
                                $file->write($data);
                                $file->close();
                                }
                                }

// View file:

<?php echo $form->create('Tip',array('type'=>'file')); ?>
        <fieldset>
                <legend><?php __('Add Tip');?></legend>
        <?php
                echo $form->input('comment_count');
                echo $form->input('name');
                echo $form->input('slug');
                echo $form->input('description');
                echo $form->input('image',array('type'=>'file'));
                echo $form->input('expires');
                echo $form->input('rating');
                echo $form->select('Tip.category_id', $cat_list, null, array(),
true);
                echo $form->input('site_id');
                echo $form->input('user_id');
                echo $form->input('Tag.name',array(
                        'type' => 'text',
                        'label' => __('Add Tags',true),
                        'after' => __('Seperate each tag with a
comma.  Eg: family, sports, icecream',true)
                                                ));
    ?>
        </fieldset>
<?php echo $form->end('Submit');?>


There is more in the controller file, but I thought I would include
just the relevant information for the time being. Is it possible that
something else in there is conflicting with the code? I tried also
adding ['tmp_name'] but no joy...

Any insight would be appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to