• <bdo id='l3nbW'></bdo><ul id='l3nbW'></ul>

    1. <legend id='l3nbW'><style id='l3nbW'><dir id='l3nbW'><q id='l3nbW'></q></dir></style></legend>

      <small id='l3nbW'></small><noframes id='l3nbW'>

      1. <tfoot id='l3nbW'></tfoot>

      2. <i id='l3nbW'><tr id='l3nbW'><dt id='l3nbW'><q id='l3nbW'><span id='l3nbW'><b id='l3nbW'><form id='l3nbW'><ins id='l3nbW'></ins><ul id='l3nbW'></ul><sub id='l3nbW'></sub></form><legend id='l3nbW'></legend><bdo id='l3nbW'><pre id='l3nbW'><center id='l3nbW'></center></pre></bdo></b><th id='l3nbW'></th></span></q></dt></tr></i><div id='l3nbW'><tfoot id='l3nbW'></tfoot><dl id='l3nbW'><fieldset id='l3nbW'></fieldset></dl></div>

        无法在 codeigniter 中保存 1 个表单中的 2 个文件

        not able to save 2 files from 1 form in codeigniter(无法在 codeigniter 中保存 1 个表单中的 2 个文件)
        <i id='DDeyD'><tr id='DDeyD'><dt id='DDeyD'><q id='DDeyD'><span id='DDeyD'><b id='DDeyD'><form id='DDeyD'><ins id='DDeyD'></ins><ul id='DDeyD'></ul><sub id='DDeyD'></sub></form><legend id='DDeyD'></legend><bdo id='DDeyD'><pre id='DDeyD'><center id='DDeyD'></center></pre></bdo></b><th id='DDeyD'></th></span></q></dt></tr></i><div id='DDeyD'><tfoot id='DDeyD'></tfoot><dl id='DDeyD'><fieldset id='DDeyD'></fieldset></dl></div>
          1. <small id='DDeyD'></small><noframes id='DDeyD'>

              • <legend id='DDeyD'><style id='DDeyD'><dir id='DDeyD'><q id='DDeyD'></q></dir></style></legend>
                  <bdo id='DDeyD'></bdo><ul id='DDeyD'></ul>

                    <tbody id='DDeyD'></tbody>
                • <tfoot id='DDeyD'></tfoot>
                • 本文介绍了无法在 codeigniter 中保存 1 个表单中的 2 个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个表单要求用户上传 2 个文件,file-upload &imgupload.我正在尝试通过 ajax 保存整个表单.

                  I have a form that requires a user to upload 2 files, file-upload & imgupload. I am trying to save the entire form through ajax.

                  表单和ajax代码

                  <form enctype="multipart/form-data" id="data">
                    <input type="file" id="file-upload" class="file-upload" name="file-upload" >
                    <input type="file" id="imgupload" class="imgupload" name="imgupload"  >
                  
                    <button type="submit" id="save" class="save-icon-btn">
                      <img src="<?php echo base_url(); ?>assets/img/Save.png">
                    </button>
                  </form>
                  
                  $("#save").click(function()
                    {
                      var form_data = new FormData($('#data')[0]);
                      jQuery.ajax(
                        {
                          type: "POST",
                          url: "<?php echo base_url(); ?>" + "comp/wfc",
                          data: form_data,
                          processData: false,
                          contentType: false,
                          success: function(res) 
                            {
                              console.log(res);
                              alert(res);
                            }
                        });
                    });
                  

                  控制器代码

                  $config['upload_path'] = './assets/file/.';
                  $config['allowed_types'] = 'gif|jpg|png|doc|txt';
                  $config['max_size'] = 1024 * 8;
                  $config['encrypt_name'] = TRUE;
                  
                  $this->load->library('upload', $config);
                  $this->upload->initialize($config);
                  
                  if (!$this->upload->do_upload('file-upload')) 
                    {
                      $error = array('error' => $this->upload->display_errors());
                       print_r($error);
                    }
                  else
                    {
                      $data = $this->upload->data();
                      echo $res = $data['file_name'];
                    }
                  
                  
                  $config2['upload_path'] = './assets/img/.';
                  $config2['allowed_types'] = 'gif|jpg|png|doc|docx|txt';
                  $config2['max_size'] = 1024 * 8;
                  $config2['encrypt_name'] = TRUE;
                  
                  $this->load->library('upload', $config2);
                  
                  if (!$this->upload->do_upload('imgupload')) 
                    {
                      $error1 = array('error' => $this->upload->display_errors());
                      print_r($error1);
                    }
                  else
                    {
                      $data1 = $this->upload->data();
                      echo $res1 = $data1['file_name'];
                    }
                  

                  问题是在控制器代码中只有 1 个文件被上传.如果我将文件上传作为第一个上传代码,那么只有这个会被上传,而 imgupload 不会被上传.

                  The issus is that in the controller code only 1 of the files get uploaded. If i keep file-upload as the first upload code then only this will get uploaded and imgupload will not get uploaded.

                  如果我将 imgupload 作为第一个上传代码,那么只有这个会被上传,而文件上传不会被上传.

                  And if i keep imgupload as the first upload code then only this will get uploaded and file-upload will not get uploaded.

                  我无法理解为什么会这样.谁能告诉我解决这个问题的方法

                  I am not able to understand why this is happening. Can anyone please tell a solution to this problem

                  推荐答案

                  请试试这个更新的功能.你在做一些奇怪的事情,例如初始化第一个而不是第二个.由于 CI 是单例,这可能会导致一些问题(并不是说这是根本原因).

                  Please try this updated function. You were doing some strange things e.g. initializing the first and not the second. As CI is a singleton, this could result in some issues (not saying that this was the root cause).

                          $this->load->library('upload');
                  
                          echo '<pre>';
                          print_r($_FILES);
                  
                          $config['upload_path'] = './assets/file/.';
                          $config['allowed_types'] = 'gif|jpg|png|doc|txt';
                          $config['max_size'] = 1024 * 8;
                          $config['encrypt_name'] = TRUE;
                          $this->upload->initialize($config);
                  
                          if (!$this->upload->do_upload('file-upload')) {
                              $error = array('error' => $this->upload->display_errors());
                              print_r($error);
                          } else {
                              $data = $this->upload->data();
                              echo $res = $data['file_name'];
                          }
                  
                          $config2['upload_path'] = './assets/img/.';
                          $config2['allowed_types'] = 'gif|jpg|png|doc|docx|txt';
                          $config2['max_size'] = 1024 * 8;
                          $config2['encrypt_name'] = TRUE;
                  
                          $this->upload->initialize($config2, true);
                  
                          if (!$this->upload->do_upload('imgupload')) {
                              $error1 = array('error' => $this->upload->display_errors());
                              print_r($error1);
                          } else {
                              $data1 = $this->upload->data();
                              echo $res1 = $data1['file_name'];
                          }
                  

                  如果它不起作用.请让我们知道 $_FILES 数组正在打印什么.

                  If it doesn't work. Please let us know what the $_FILES array is printing.

                  更新:

                  它不起作用,因为 $this->load->library('upload', $config2);.当 CI 看到 load 时,它首先检查是否加载了类,而不管传递的参数如何,因为它已经加载了这一行被忽略并且正在使用来自 $config 的设置(第一个图像上传).

                  It wasn't working because $this->load->library('upload', $config2);. When CI sees load it checks first if the class is loaded regardless of the parameters being passed, as it was already loaded this line was ignored and the settings from $config (the first image upload) were being used.

                  这篇关于无法在 codeigniter 中保存 1 个表单中的 2 个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                      <tbody id='YstVN'></tbody>
                  • <i id='YstVN'><tr id='YstVN'><dt id='YstVN'><q id='YstVN'><span id='YstVN'><b id='YstVN'><form id='YstVN'><ins id='YstVN'></ins><ul id='YstVN'></ul><sub id='YstVN'></sub></form><legend id='YstVN'></legend><bdo id='YstVN'><pre id='YstVN'><center id='YstVN'></center></pre></bdo></b><th id='YstVN'></th></span></q></dt></tr></i><div id='YstVN'><tfoot id='YstVN'></tfoot><dl id='YstVN'><fieldset id='YstVN'></fieldset></dl></div>

                      • <bdo id='YstVN'></bdo><ul id='YstVN'></ul>

                            <tfoot id='YstVN'></tfoot>

                            <legend id='YstVN'><style id='YstVN'><dir id='YstVN'><q id='YstVN'></q></dir></style></legend>

                            <small id='YstVN'></small><noframes id='YstVN'>