Here cakephp image upload working fine without ajax.After using ajax, data is inserted without image directory.
Here is my model code
public function processCoverUpload($check = array()) {
if (!is_uploaded_file($check['product_image']['tmp_name'])) {
return FALSE;
}
if (!move_uploaded_file($check['product_image']['tmp_name'], WWW_ROOT . 'img' . DS . 'uploads' . DS . $check['product_image']['name'])) {
return FALSE;
}
$this->data[$this->alias]['product_image'] = 'uploads/'. $check['product_image']['name'];
return TRUE;
}
Here the controller
if ($this->request->is('post')) {
$this->MadProduct->create();
$data = $this->request->data['MadProduct'];
if (!$data['product_image']['name']) {
unset($data['product_image']);
}
if ($this->MadProduct->save($data)) {
$this->Session->setFlash(__('The mad product has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The mad product could not be saved. Please, try again.'));
}
}
Here is the view file field
echo $this->Form->input('product_image',array('type' => 'file','label' => false,));
Here is the js submission button
<?php echo $this->Js->submit('Submit',array(
'before'=>$this->Js->get('#sending')->effect('fadeIn',array('speed' => 'slow')),
'success'=>$this->Js->get('#sending')->effect('fadeOut',array('speed' => 'slow')),
'class' => 'btn btn-danger',
'style'=>'width:45%;margin-top:1%;height:30px;')
);
?>
How I will send image directory by jshelper ?