首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cakephp-2.4:应用jshelper ajax提交后不发送图像目录

cakephp-2.4:应用jshelper ajax提交后不发送图像目录
EN

Stack Overflow用户
提问于 2014-10-30 07:09:29
回答 1查看 201关注 0票数 0

这里cakephp的图像上传工作很好,没有ajax.After使用ajax,数据是插入没有图像目录。

这是我的模型代码

代码语言:javascript
复制
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;
        }

在这里,控制器

代码语言:javascript
复制
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.'));
            }
        }

以下是视图文件字段

代码语言:javascript
复制
echo $this->Form->input('product_image',array('type' => 'file','label' => false,));

这是js提交按钮

代码语言:javascript
复制
 <?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?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-30 12:20:08

JS助手不支持文件上传,这需要使用“新的”XHR2特性。

您可以扩展JS助手/引擎并添加对文件的支持,但是由于JS助手无论如何都是deprecated,所以我建议直接使用JavaScript。有足够的例子展示如何通过AJAX上传文件。

How can I upload files asynchronously?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26647018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档