doujingke4981
2017-03-29 08:41
浏览 56
已采纳

Codeigniter文件上传显示错误

Controller code

        $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 code:

<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>

Whenever I am uploading file it displaying warning is_uploaded_file() expects parameter 1 to be string, array given. How can I resolve it?

图片转代码服务由CSDN问答提供 功能建议

控制器代码

  $ config ['upload_path'] =  './uploads/'.$random;
 $ config ['allowed_types'] ='gif | jpg | png'; 
 $ config ['max_size'] = 100; 
 $ config ['max_width'] =  1024; 
 $ config ['max_height'] = 768; 
 
 $ this-&gt; load-&gt; library('upload',$ config); 
 
 if(!$ this-&gt; upload  - &gt; do_upload('imageupload'))
 {
 $ error = array('error'=&gt; $ this-&gt; upload-&gt; display_errors()); 
} 
 else 
 {\  n $ data = array('upload_data'=&gt; $ this-&gt; upload-&gt; data()); 
} 
 print_r($ data); 
   
 \  n 

HTML代码:

 &lt; form role =“form”enctype =“multipart / form-data”accept-charset =“utf-8”name =“  formname“id =”formname“method =”post“action =”http://www.example.com/Property/post“&gt; 
&lt; input type =”file“class =”default“id =”imageupload1  “ 名称 =“imageupload []”&gt; 
&lt; / form&gt; 
   
 
 

每当我上传文件时,它显示警告is_uploaded_file()要求参数1为字符串,数组 给出。 我该如何解决?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • douchen2595 2017-03-29 10:17
    最佳回答

    try this

          //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 
    
    
            }
            }
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题