【问题标题】:cakephp-2.4:Image directory not sending after applying jshelper ajax submissioncakephp-2.4:应用jshelper ajax提交后图像目录不发送
【发布时间】: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


    【解决方案1】:

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

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

    How can I upload files asynchronously?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-25
      • 2011-01-31
      相关资源
      最近更新 更多