when i update all 3 images then it will work fine. if i dont update all 3 then its work fine . but it will not work if i update 1 and not other. even it will not work if i update 2 and not 1 . may be its my if else cond. error. but i cant fig it out. so plz help me thanks :)
public function edit($id=2) {
$this->helpers = array('TinyMCE.TinyMCE');
$this->layout = 'adminpanel';
if (!$id) {
throw new NotFoundException(__('Invalid post'));
}
$this->layout = 'adminpanel';
//save data
if ($this->request->is(array('post', 'put'))) {
$this->Home->id = $id;
//Save image
if(is_uploaded_file($this->request->data['Home']['image_1']['tmp_name']))
{
$fileNameFull = $this->request->data['Home']['image_1']['name'];
$uploadFolder = "upload";
//full path to upload folder
$uploadPath = WWW_ROOT . $uploadFolder;
$oldFile = $uploadPath.'/'.$fileNameFull;
move_uploaded_file(
$this->request->data['Home']['image_1']['tmp_name'],$oldFile
);
$newFile = WWW_ROOT.'courseImages/thumb/'.$fileNameFull;
$image = new ImageResizeComponent();
$quality = 100; // image resize for thumb
$height = 40;
$width = 60;
$this->ImageResize->resize($oldFile, $newFile, 60,60,$quality);
$this->request->data['Home']['image_1'] = $fileNameFull;
}
if(is_uploaded_file($this->request->data['Home']['image_3']['tmp_name']))
{
$fileNameFull = $this->request->data['Home']['image_3']['name'];
$uploadFolder = "upload";
//full path to upload folder
$uploadPath = WWW_ROOT . $uploadFolder;
$oldFile = $uploadPath.'/'.$fileNameFull;
move_uploaded_file(
$this->request->data['Home']['image_3']['tmp_name'],$oldFile
);
$newFile = WWW_ROOT.'courseImages/thumb/'.$fileNameFull;
$image = new ImageResizeComponent();
$quality = 100; // image resize for thumb
$height = 40;
$width = 60;
$this->ImageResize->resize($oldFile, $newFile, 60,60,$quality);
$this->request->data['Home']['image_3'] = $fileNameFull;
}
if(is_uploaded_file($this->request->data['Home']['image_2']['tmp_name']))
{
$fileNameFull = $this->request->data['Home']['image_2']['name'];
$uploadFolder = "upload";
//full path to upload folder
$uploadPath = WWW_ROOT . $uploadFolder;
$oldFile = $uploadPath.'/'.$fileNameFull;
move_uploaded_file(
$this->request->data['Home']['image_2']['tmp_name'],$oldFile
);
$newFile = WWW_ROOT.'courseImages/thumb/'.$fileNameFull;
$image = new ImageResizeComponent();
$quality = 100; // image resize for thumb
$height = 40;
$width = 60;
$this->ImageResize->resize($oldFile, $newFile, 60,60,$quality);
$this->request->data['Home']['image_2'] = $fileNameFull;
}
else{//Img not uploaded
//**TWO GOLDEN LINES OF YOUR LIFE**
$tourForImg = $this->Home->findByid($id);
$this->request->data['Home']['image_1'] = $tourForImg['Home']['image_1'];
$this->request->data['Home']['image_2'] = $tourForImg['Home']['image_2'];
$this->request->data['Home']['image_3'] = $tourForImg['Home']['image_3'];
//**TWO GOLDEN LINES OF YOUR LIFE**
}
if ($this->Home->save($this->request->data)) {
$this->Session->setFlash(__('Unable to hppp,ee your schedule.'));
//Save image
$this->Session->setFlash('Your home slider image has been saved343434.', 'default',array('class' => 'alert alert-success'));
//$this->Session->setFlash(__('Your home has been updated.'));
return $this->redirect(array('controller'=>'homes','action' => 'edit'));
$this->Session->setFlash(__('Unable to update your Tour.'));
}
}
$home = $this->Home->findByid($id);
if (!$home) {
throw new NotFoundException(__('Invalid post'));
}
if (!$this->request->data) {
$this->request->data = $home;
}
}
echo $this->Form->create('Home',array('autocomplete' => 'off','enctype'=>'multipart/form-data'));
echo $this->Form->input('image_1', array('type' => 'file')); // then display images
//above same for 3 image
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->end('Save Post'); ?>