Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter文件上载显示错误_Php_Html_Codeigniter - Fatal编程技术网

Php Codeigniter文件上载显示错误

Php Codeigniter文件上载显示错误,php,html,codeigniter,Php,Html,Codeigniter,控制器代码 $config['upload_path'] = './uploads/'.$random; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = 100; $config['max_width'] = 1024; $config['max_height'

控制器代码

        $config['upload_path']          = './uploads/'.$random;
        $config['allowed_types']        = 'gif|jpg|png';
        $config['max_size']             = 100;
        $config['max_width']            = 1024;
        $config['max_height']           = 768;

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

        if ( ! $this->upload->do_upload('imageupload'))
        {
            $error = array('error' => $this->upload->display_errors());
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
        }
        print_r($data);
HTML代码:

<form role="form" enctype="multipart/form-data" accept-charset="utf-8" name="formname" id="formname"  method="post" action="http://www.example.com/Property/post">
    <input type="file" class="default" id="imageupload1" name="imageupload[]">
</form>

每当我上传文件时,它都会显示警告信息。文件希望参数1是字符串,数组给定。我如何解决它?

您的输入名称可能不应包含括号:

<input type="file" class="default" id="imageupload1" name="imageupload">
试试这个

      //place this code in your function for multiple image upload
   $data = array();
    if(!empty($_FILES['imageupload']['name']))
    {
        $filesCount = count($_FILES['imageupload']['name']);
          for($i = 0; $i < $filesCount; $i++){
            $_FILES['imageupload']['name'] = $_FILES['imageupload']['name'][$i];
            $_FILES['imageupload']['type'] = $_FILES['imageupload']['type'][$i];
            $_FILES['imageupload']['tmp_name'] = $_FILES['imageupload']['tmp_name'][$i];
            $_FILES['imageupload']['error'] = $_FILES['imageupload']['error'][$i];
            $_FILES['imageupload']['size'] = $_FILES['imageupload']['size'][$i];

            $uploadPath = 'uploads/';
            $config['upload_path'] = $uploadPath;
            $config['allowed_types'] = 'gif|jpg|png';

            $this->load->library('upload', $config);
            $this->upload->initialize($config);
            if($this->upload->do_upload('imageupload')){
                $fileData = $this->upload->data();
                $uploadData[$i]['file_name'] = $fileData['file_name'];
                $uploadData[$i]['created'] = date("Y-m-d H:i:s");
                $uploadData[$i]['modified'] = date("Y-m-d H:i:s");
            }
        }

        if(!empty($uploadData)){
            //Insert file  into the database using your model 


        }
        }

因为您在输入字段中指定了imageupload[]名称意味着数组,所以您是否正在处理多个文件上载?是的,我正在处理多个文件上载我认为您应该在控制器imageupload[0]或其他类似内容中使用。如果看不到完整代码,则无法正确建议解决方案。我如何上载多个文件?如果您猜到任何答案,请使用注释。我如何同时上载多个文件?