【发布时间】:2014-10-30 07:09:29
【问题描述】:
在没有ajax的情况下,这里cakephp图片上传工作正常。使用ajax后,数据插入没有图像目录。
这是我的模型代码
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;
}
这里是控制器
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.'));
}
}
这里是视图文件字段
echo $this->Form->input('product_image',array('type' => 'file','label' => false,));
这里是js提交按钮
<?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;')
);
?>
我将如何通过 jshelper 发送图像目录?
【问题讨论】:
标签: cakephp cakephp-2.4