Wednesday, July 16, 2014

Re: Form Uploaded Image not exist when Edit form

Hello Kimi.
What i did was to show the image if exist, when edit, and if you not upload other,do nothing:

Edit page
echo $this->Html->image("user_icons/".$photo, $options =  array('alt' => 'Icon User', 'width' => '150px'));

echo $this->Form->input('User.photo', array('type' => 'file'));


UserController edit function
if ($this->request->is(array('post', 'put'))) {
$tmp_name = $this->request->data['User']['photo']['tmp_name'];
$filename = $this->code().'_'.$this->request->data['User']['photo']['name'];
$uploads_dir = WWW_ROOT.'img'.DS.'user_icons'.DS. $filename;
$this->request->data['User']['photo'] = $filename;
//pr($this->request->data); die();
if ($this->User->save($this->request->data)) {
move_uploaded_file($tmp_name, $uploads_dir);  
$this->Session->setFlash(__('The user has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
} else {

$options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
$this->request->data = $this->User->find('first', $options);
$this->set('photo', $this->request->data['User']['photo']); 
}

Hope that help you.

Best Regards, Stefan

miercuri, 16 iulie 2014, 10:25:55 UTC+3, Kimi Sharma a scris:
I have create form with some text field and one image field. It add successfully after submit.

but when i edit this form.. my form fields prefilled value exist of that particular id (to which i edit) . but form image not show existing image and request to enter new image. 

kindly let me know solution. as i want to my previous image already uploaded when i edit this form.. if i upload new then it replace. otherwise same image uploaded.

kindly revert asap. 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: