【问题标题】:Code igniter File-Upload is not getting the valueCodeigniter 文件上传没有获得价值
【发布时间】:2017-01-13 01:52:46
【问题描述】:

我已经完成了这个以及它与我以前的项目的合作。现在,我正在做一个新项目,并试图将我的代码复制并粘贴到文件上传中。它没有任何价值。我的问题是为什么我的文件上传没有获得价值?

注意:我已经在我的助手中声明了表单,并且可能文件夹已经存在.. 我的列的名称是 img_jumbotron,我的 CI 版本是 3.3(最新)

查看

<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Upload New Image</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="titleLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header modal-header-success">
        <button type="button" class="close btn btn-primary" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="titleLabel">New Image</h4>
        </div>
        <div class="modal-body">
          <div class="container">
            <div class="panel-body">
              <div class="text-content">
                <div class="col-md-2 col-lg-5">
                  <br>
                  <form method="post" enctype="multipart/form-data" action="<?= base_url().'Administrator/addContent/'?>">
                    dklfjkdf
                    <input type ="text" name ="example">
                    <div class="form-group">
                      <label>Image</label>
                      <input type="file" required class="form-control" name="userfile"/> 
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <span class="pull-right">
             <button type="submit" class="btn btn-success">Upload File</button>
             <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
           </span>
         </form>
       </div>
     </div>
   </div>
 </div>

控制器

public function addContent()
    {
      $config['upload_path'] = './uploaded/';   
      $config['max_size'] = '2048000';
      $config['overwrite'] = TRUE;          
      $config['allowed_types'] = '*';

      $this->load->library('upload', $config);

      $this->load->library('form_validation');
      $this->form_validation->set_error_delimiters('<div class="alert alert-danger" role="alert">', '</div>');
      $example = $_POST['example'];
      $example = $this->input->post('userfile');
      print_r($example);die;
      if ($this->form_validation->run() == FALSE || !$this->upload->do_upload('userfile'))
      { 
          echo ('ksldfhsdj');
      } 
      else 
      {

          $content = array(
              'img_jumbotron' => $this->input->post('userfile'),
                'upload_data' => $this->upload->data()
              );

          print_r($content);die;
          $this->AdminModel->addContent($content); 
          redirect('Administrator/headContent');
      }

型号

public function addContent($content)
    {

        $content = array(
            'img_jumbotron' => $this->input->post('userfile'),
            'img_jumbotron' => $this->upload->data('file_name')
            );
        $this->db->insert('content', $content);
    }

【问题讨论】:

  • HTML 头疼...
  • @JBES 是什么意思?
  • 只是评论大量DIVs。

标签: php codeigniter file-upload


【解决方案1】:

您可以在浏览器上使用开发人员工具并检查 NETWORK(我猜是 chrome)选项卡并检查您的应用程序是否正在发送文件。

还有:

action="<?=base_url().'Administrator/addContent/'?>"

我认为您应该删除此“&lt;?=”上的等号。

【讨论】:

  • 先生,相当于 是(= ?>)
  • 我明白了.. 没用过.. 那么,我认为你需要使用开发工具来解决这个问题.. :)
猜你喜欢
  • 2016-10-20
  • 2021-03-28
  • 2016-01-30
  • 2018-04-08
  • 2018-04-09
  • 2012-06-24
  • 1970-01-01
  • 2012-07-20
  • 2021-06-21
相关资源
最近更新 更多