Add of image upload is working fine ... but in case of edit there is no upload happening. DB retain old image data. I am using Qimage for file copy.
Controller of image upload
public function edit($id=NULL){
if (!$id) {
throw new NotFoundException(__('Invalid Movie'));
}
$movie = $this->Movie->findById($id);
if (!$movie) {
throw new NotFoundException(__('Invalid Movie'));
}
if ($this->request->is(array('post', 'put'))) {
$this->Movie->id = $id;
if(!empty($this->request->data['Movie']['image']['name'])){
$data['file']= $this->request->data['Movie']['image'];
$data['path']= WWW_ROOT . 'img/';
unset($this->request->data['Movie']['image']);
$this->request->data['Movie']['image']=$this->Qimage->copy($data);
$this->Qimage->resize(array(
'width'=>200, 'height'=>300,
'file'=>WWW_ROOT . 'img/'.$this->request->data['Movie']['image'],
'output'=>WWW_ROOT . 'img/'
));
}
else{
unset($this->request->data['Movie']['image']);
}
if ($this->Movie->saveAll($this->request->data['Movie'])) {
$this->Session->setFlash(__('Movie has been updated.'));
return $this->redirect(array('controller' => 'movies','action' => 'movielist'));
}else{
$this->Session->setFlash(__('Unable to update movie.'));
}
}
if (!$this->request->data) {
$this->request->data = $movie;
}
}
please help. View of Edit function-
<?php echo $this->Form->create('Movie');?>
<fieldset>
<legend><?php echo __('Update Movie'); ?></legend>
<?php
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->input('name');
echo $this->Form->input('about');
echo $this->Form->file('Movie.image');
echo $this->Form->input('budget');
echo $this->Form->submit('Update Movie', array('class' => 'form-submit', 'title' => 'Click here to update the movie'));
?>
</fieldset>
<?php echo $this->Form->end(); ?>