how can convert $files contain to array?

后端 未结 6 1384
[愿得一人]
[愿得一人] 2020-12-11 14:01

How do I solve this error?

A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: admin/tour.php
Line Numbe         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 14:23

    I figure I would just share how I handle multiple uploads in CI, it's a little different than your method:

    Form looks like this:

    
    

    Upload/multiple_upload function in controller looks like this:

    function multiple_upload()
    {
        $config['upload_path'] = './userpics/originals/'; // server directory
        $config['allowed_types'] = 'gif|jpg|png'; // by extension, will check for whether it is an image
        $config['max_size']    = '512'; // in kb
        //$config['max_width']  = '1024';
        //$config['max_height']  = '768';
    
        $this->load->library('myupload');
        $error = array(); $data = array();
        for ($i=0;$imyupload->initialize($config);
                if (!$this->myupload->do_upload('userfile',$i)) {
                        $error[] = $this->myupload->display_errors();
                }
                $data[$i] = $this->myupload->data(); //gradually build up upload->data()
        }
    
        if ( count($error) > 0 )        
        {
            print_r($error);
        }    
        else
        {
            print_r($data);
        }
    }    
    

    At this point I made a copy of CI upload class, and pasted it into my applications library directory. A few changes need to be made. I named it myupload.

    @ Line 143:

    public function do_upload($field = 'userfile')
    

    change to

    public function do_upload($field = 'userfile', $i = 0)
    

    Any lines in this function above line 200, you must add [$i] to the end of the $_FILES variables.

    Example:

    is_uploaded_file($_FILES[$field]['tmp_name'])
    

    change to:

    is_uploaded_file($_FILES[$field]['tmp_name'][$i])
    

    There are 9 lines to be updated.

提交回复
热议问题