Is it possible to multi file upload usign codeigniter 1.7 and a loop?

后端 未结 2 1078
天涯浪人
天涯浪人 2021-01-22 02:33

I\'ve been trying to do a multi file upload with codeigniter 1.7. I\'m having issues to say the least!

I know its an old version but that\'s what I\'ve got to work with.

相关标签:
2条回答
  • 2021-01-22 02:54

    Hope This will help

    $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'];
    
                } } } }
    
    0 讨论(0)
  • 2021-01-22 03:06

    Yes, can loop through $_FILES... although you probably shouldn't name an array an "object", it's a little confusing.

    Here's a user manual I found, specifically for the uploads in 1.7, it appears to be substantially similar to 3.0.3. http://www.standoffsystems.com/ci/user_guide/libraries/file_uploading.html

    First, make sure your destination folder is set to 777

    your config is outside the foreach() and the $this->upload->initialize($config); is inside, you don't need to initialize it each time since the $config items are, essentially, static. This isn't likely to fix your issue though.

    Try this instead:

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

    I see you're not echoing out any errors, what happens if you do?

     echo $this->upload->display_errors();
    
    0 讨论(0)
提交回复
热议问题