0

I have a Button with with unlimited add files uploads it's working fine. But i have error in upload multiple files. Files are separate. I got all the files with whole array but there is a some problem occurs in $this->upload->do_upload():

is_uploaded_file() expects parameter 1 to be string, array given

I read and tried multiple-files-upload-array-with-codeigniter-2-0. It's similar to my question but it didn't work.

<div class="form-group">
    <label>Menu</label>
    <div id="text">
        <div class="abc">
            <input class="input_file" name="userfile[]" type="file"/>
            <input class="add_input" type="button" id="add-file-field" name="add" value="Add Photo" />
        </div>
    </div>
    <input class="" type='hidden' name="action" value="uploadfiles" />
    <input type="hidden" value="Upload File" />
</div>

This html file calls Javascript and it's looks like below picture.

enter image description here

Now my function is,

public function insert_gallery()
{   
    isset($_REQUEST['action']) ? $action = $_REQUEST['action'] : $action = '';
    if($action == 'uploadfiles')
    {
        //define where the files will be uploaded
        echo "<pre>";
        print_r($_FILES);
        $x=0;  
        foreach ($_FILES['userfile']['name'] as $key => $value)
        {  
            echo $image_name = $_FILES['userfile']['name'][$key];
            echo $unique_name = time().$image_name;
            $x++;  
            $config =  array(
              'upload_path'     => "./public/business_gallery",
              'allowed_types'   => "gif|jpg|png|jpeg|pdf",
              'overwrite'       => TRUE,
              'max_size'        => "2048000",  // Can be set to particular file size
          'max_height'      => "768",
          'max_width'       => "1024",
        );    
        print_r($config);
        $this->load->library('upload',$config);
        if($this->upload->do_upload())
        {
            echo 1;
        }
        else
        {
            echo 0;
        }
    }
}

}

I got Files in array but there is problem occurs in $this->upload->do_upload()

Array of files

Array
(
    [userfile] => Array
        (
            [name] => Array
                (
                    [0] => Chrysanthemum.jpg
                )

            [type] => Array
                (
                    [0] => image/jpeg
                )

            [tmp_name] => Array
                (
                    [0] => C:\xampp\tmp\phpD65E.tmp
                )

            [error] => Array
                (
                    [0] => 0
                )

            [size] => Array
                (
                    [0] => 879394
                )

        )

    [data] => Array
        (
            [name] => Array
                (
                    [0] => Jellyfish.jpg
                    [1] => Penguins.jpg
                    [2] => Tulips.jpg
                )

            [type] => Array
                (
                    [0] => image/jpeg
                    [1] => image/jpeg
                    [2] => image/jpeg
                )

            [tmp_name] => Array
                (
                    [0] => C:\xampp\tmp\phpD67E.tmp
                    [1] => C:\xampp\tmp\phpD67F.tmp
                    [2] => C:\xampp\tmp\phpD68F.tmp
                )

            [error] => Array
                (
                    [0] => 0
                    [1] => 0
                    [2] => 0
                )

            [size] => Array
                (
                    [0] => 775702
                    [1] => 777835
                    [2] => 620888
                )

        )

)
Chrysanthemum.jpg1468415399Chrysanthemum.jpgArray
(
    [upload_path] => ./public/business_gallery
    [allowed_types] => gif|jpg|png|jpeg|pdf
    [overwrite] => 1
    [max_size] => 2048000
    [max_height] => 768
    [max_width] => 1024
)
Community
  • 1
  • 1
Bhavin
  • 2,070
  • 6
  • 35
  • 54

0 Answers0