Hi Foroct,
1. Handling just the file upload:
You just posted the file to your action (via XHR) and $this->data['media']
now contains the file upload array. Image is a model available in the
controller which has generator and transfer behaviors attached to it.
$file = $this->Image->transfer($this->data['media']); // handle upload
$this->Image->make($file); // generate versions
You now return the path to the file in i.e. a JSON response.
2. Associating the file with the record:
How you do this depends on how your models are related to each other and
what kind of model structure you are using. However let's say you're
actually saving a Post and that Post hasMany Image (see above). The Image
model has all the media behaviors attached to it. In case this assumption
doesn't apply to your scenario you must adapt it.
$this->data contains sth like this:
array(
'Post' => array('title' => '...'),
'Image' => array('file' => the path to the file from step 1)
)
$this->Post->Image->disable('Transfer'); // we already have upload the file
$this->Post->Image->disable('Generator'); // already have versions of it
$this->Post->saveAll($this->data);
Hope that helps,
- David
--
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
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php