On 6/25/06, linkingarts <[EMAIL PROTECTED]> wrote: > > I want to populate a row in a database, and upload an image (into a > directory, not the db) from the same form. I'd also like to grab the > $_FILES[filename][name] param to go into the database. > > I have NO idea how to do this in Cake - no problem for me otherwise, > but I don't even know where to begin when it comes to doing this > w/Cake. (MVC Kung Fu is weak) > > Right now I've got a controller that functions fine to CRUD the data. I > tried out the Files Component by Nicolas Cohen (put it in > app/controllers/components as files.php
> > http://cakeforge.org/snippet/detail.php?type=snippet&id=7 > > added this to the view: > > <?php echo $html->file('imageFile') ?> > > and this to the controller: > > add() > { > yada yada... > > if ($this->Business->save($this->params['data'])) > { > if ($_FILES['imageFile']) > { > $this->Files->saveAs('imageFile', $imgId, > WWW_ROOT . > 'img'.DS.'uploads'.DS); > } > > //cleanUpFields(effective_to_dt); > $this->flash('Your listing has been > saved.','/businesses'); > } > else { yada yada } > } > > I get this error: > > Notice: Undefined index: imageFile in > /myserver/app/controllers/businesses_controller.php on line 219 > > Is it trying to add imageFile to the db? > > FWIW, the upload dir is 777, and the form has the correct enctype. > > I've spent WAY too many hours on this one, searching the manual, wiki, > group, lurking on IRC... it's driving me nuts! any help is GREATLY > appreciated. If I can get it working I'll probably write a tutorial to > save a future baker this headache. firstly, make sure you have the correct enctype for your form: <?php echo $html->formTag('/controller/action/','post',array('enctype'=>'multipart/form-data')); ?> then, you can access the imageFile like so in your controller: $this->params['form']['imageFile'] not used the files component, so can't help with that, but the above should get you started. it's not very tricky really, once you know how cake works with form vars. hth jb jon bennett t: +44 (0) 1225 341 039 w: http://www.jben.net/ iChat (AIM): jbendotnet Skype: jon-bennett --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~----------~----~----~----~------~----~------~--~---
