Friday, February 24, 2012

How to handle FILE input type when saving form information?

Hi:
I'm having some problems handling file uploads and database saving. I have a table where I need to store the route where uploaded files are saved but not know how to achieve this. I found this  http://cakebaker.42dh.com/2006/04/15/file-upload-with-cakephp/  and I'm trying to adjust my code to fit the requirements. Now my code is this one:

public function add() {
if ($this->request->is('post') && is_uploaded_file($this->request->data['Information']['picture']['tmp_name'])) {
// Handling file uploads
$fileData = fread(fopen($this->request->data['Information']['picture']['tmp_name'], "r", $this->request->data['Information']['picture']['size']));
$this->data['Information']['name'] = $this->request->data['Information']['picture']['name']; 
$this->Information->create();
if ($this->Information->saveAll($this->request->data)) {
$this->Session->setFlash(__('The information has been saved'), 'flash_success');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The information could not be saved. Please, try again.'), 'flash_error');
}
}
$countries = $this->Information->Country->find('list');
$this->set(compact('countries'));
}

and have two questions around it: how to setup where uploaded files goes? how to add this route to query? I mean for save the route in my DB
Any advice or help?
Cheers
Ing. Reynier Pérez Mira

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: