【问题标题】:Is it possible to multi file upload usign codeigniter 1.7 and a loop?是否可以使用 codeigniter 1.7 和循环进行多文件上传?
【发布时间】:2016-04-17 05:31:49
【问题描述】:

我一直在尝试使用 codeigniter 1.7 进行多文件上传。至少可以说我有问题!

我知道它是一个旧版本,但这就是我必须使用的。

我可以循环 $_FILES 数组并上传每个数组吗?它似乎不起作用。

这是我得到的?

        $dir_name = $this->input->post('dir');

    $file_path = "./system/application/views/courses/course/";

    $full_file_path = $file_path . $dir_name;


    if (!file_exists($full_file_path)) {
        mkdir($full_file_path, 0777, true);
    }

    $config['upload_path'] = $full_file_path;
    $config['allowed_types'] = 'php|js|html';

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

    foreach ($_FILES as $files => $fileObject)  //
    {
        if (!empty($fileObject['name']))
        {
            $this->upload->initialize($config);
            if (!$this->upload->do_upload($files))
            {
                $errors = $this->upload->display_errors();
            }
            else
            {
                echo "It worked";
            }
        }
    }

这可能吗?

此代码运行但不上传文件?!

【问题讨论】:

    标签: php codeigniter file-upload


    【解决方案1】:

    是的,可以循环访问 $_FILES...虽然您可能不应该将数组命名为“对象”,但这有点令人困惑。

    这是我找到的用户手册,专门用于 1.7 中的上传,它似乎与 3.0.3 大体相似。 http://www.standoffsystems.com/ci/user_guide/libraries/file_uploading.html

    首先,确保您的目标文件夹设置为 777

    您的configforeach() 之外,而$this->upload->initialize($config); 在里面,您不需要每次都初始化它,因为$config 项目本质上是静态的。不过,这不太可能解决您的问题。

    试试这个:

    $config['upload_path'] = $full_file_path;
    $config['allowed_types'] = 'php|js|html';
    
    $this->load->library('upload', $config);
    
    foreach (){
       $this->upload->initialize($config); <-- remove this
       ...
    }
    

    我看到你没有回显任何错误,如果你这样做会发生什么?

     echo $this->upload->display_errors();
    

    【讨论】:

      【解决方案2】:

      希望对你有帮助

      $name_array=array(); 
      $count = count($_FILES['userfile']['size']);
      foreach($_FILES as $key => $value)
      {
          for ($s = 0; $s < $count; $s++)
          {
      $_FILES['userfile']['name'] = $value['name'][$s];
              $_FILES['userfile']['type'] = $value['type'][$s];
              $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
              $_FILES['userfile']['error'] = $value['error'][$s];
              $_FILES['userfile']['size'] = $value['size'][$s];
              $config['upload_path'] = "uploads/item_images/itemimage/original/";
              $config['allowed_types'] = 'gif|jpg|png';
              $config['max_size'] = '8000';
              $config['max_width'] = '10240';
              $config['max_height'] = '7680';
              $this->load->library('upload', $config);
              if ($this->upload->do_upload("image"))
              {
                  $data = $this->upload->data();
                if ($this->image_moo->errors)
                  {
                      print $this->upload->display_errors();
                  }
                  else
                  {
                      $name_array[] = $data['file_name'];
      
                  } } } }
      

      【讨论】:

      • 你先生/小姐是个传奇!这几天一直在努力!!
      猜你喜欢
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      • 2016-10-19
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多