这里cakephp的图像上传工作很好,没有ajax.After使用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?
发布于 2014-10-30 12:20:08
JS助手不支持文件上传,这需要使用“新的”XHR2特性。
您可以扩展JS助手/引擎并添加对文件的支持,但是由于JS助手无论如何都是deprecated,所以我建议直接使用JavaScript。有足够的例子展示如何通过AJAX上传文件。
https://stackoverflow.com/questions/26647018
复制相似问题