it will display error if i update other filed and not image.
public function edit($id = null) {
$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->Tour->id = $id;
//Save image
if(is_uploaded_file($this->request->data['Tour']['varbigimg']['tmp_name']))
{
$fileNameFull = $this->request->data['Tour']['varbigimg']['name'];
$uploadFolder = "upload";
//full path to upload folder
$uploadPath = WWW_ROOT . $uploadFolder;
$oldFile = $uploadPath.'/'.$fileNameFull;
move_uploaded_file(
$this->request->data['Tour']['varbigimg']['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['Tour']['varbigimg'] = $fileNameFull;
}
else{//Img not uploaded
$this->request->data['Tour']['vartitle']= $this->data['Tour']['vartitle'];
$this->request->data['Tour']['varsubtitle']= $this->data['Tour']['varsubtitle'];
$this->request->data['Tour']['txtsortdesc']= $this->data['Tour']['txtsortdesc'];
$this->request->data['Tour']['txtdeasc']= $this->data['Tour']['txtdeasc'];
$this->request->data['Tour']['vardeparts']= $this->data['Tour']['vardeparts'];
$this->request->data['Tour']['decadultprice']= $this->data['Tour']['decadultprice'];
$this->request->data['Tour']['decchildprice']= $this->data['Tour']['decchildprice'];
$this->request->data['Tour']['varimgtitle']= $this->data['Tour']['varimgtitle'];
$this->request->data['Tour']['enumstatus']= $this->data['Tour']['enumstatus'];
$this->request->data['Tour']['id']= $this->data['Tour']['id'];
//In this way do for All Except Image.
}
// pr($this->$this->request->data);
if ($this->Tour->save($this->request->data)) {
$this->Session->setFlash(__('Unable to add your schedule.'));
//Save image
$this->Session->setFlash(__('Your tour has been updated.'));
return $this->redirect(array('controller'=>'admin','action' => 'tour'));
$this->Session->setFlash(__('Unable to update your Tour.'));
}
}
$tour = $this->Tour->findByid($id);
if (!$tour) {
throw new NotFoundException(__('Invalid post'));
}
if (!$this->request->data) {
$this->request->data = $tour;
}
}
my cont code my view is below. so when i upload image it will work fine. but in edit if i dont upload image then it display array to sting error. means it not take ast image. thanks
echo $this->Form->create('Tour',array('autocomplete' => 'off','enctype'=>'multipart/form-data'));
echo $this->Form->input('varbigimg',array('type' => 'file'));?>