Php 使用2个输入上载文件

Php 使用2个输入上载文件,php,html,arrays,codeigniter,upload,Php,Html,Arrays,Codeigniter,Upload,我想上传带有2个输入文件的文件。第一次只输入一个文件,第二次输入多个文件。第一次输入保存到“/asset/sopic”,第二次保存到“/asset/sdpic”。 以下是我的代码(视图): 照片 “alt=“…”id=“foto”class=“img响应中心块”> 详细照片 这就是模型: $config['upload_path'] = './asset/sopic/'; //On "sopic" upload $co

我想上传带有2个输入文件的文件。第一次只输入一个文件,第二次输入多个文件。第一次输入保存到“/asset/sopic”,第二次保存到“/asset/sdpic”。 以下是我的代码(视图):


照片
“alt=“…”id=“foto”class=“img响应中心块”>
详细照片

这就是模型:

$config['upload_path'] = './asset/sopic/'; //On "sopic" upload
                                    $config['allowed_types'] = 'jfif|jpg|jpeg|png|gif'; //Pitcure Only
                                    $config['max_size'] = '2048'; //2MB
                                    $config['encrypt_name'] = TRUE;
                                    //$config['file_name'] = $prna; //set new Name
                                    $this->load->library('upload', $config); //load library upload

                                    $id = $this->loginm->getshopid(array("nama" => $nam), array("exp" => $dat));

                                    //Photos is detected OK
                                    if ($this->upload->do_upload('foto')){
                                        //Get Filename
                                        $fnm = $this->upload->data('file_name');
                                        chmod('./asset/sopic/'.$fnm, 0777);
                                        //Update user table on "Photo" column where Mail as ID
                                        $this->loginm->upvo(array('by_user' => $mail), array('kode' => $kod), array('photo' => $fnm));

                                        $errmsg[] = array('ico' => 'ti-check', 'txt' => '<b>OK: Shop Photo </b><br><i>'.$tus.' added!</b>',
                                            'typ' => 'success');
                                    }else{
                                        $errmsg[] = array('ico' => 'ti-info', 'txt' => '<b>Info: </b><br><i>'.$this->upload->display_errors().'</b>',
                                            'typ' => 'warning');
                                    }

                                    if(!empty($fpi)){
                                        $x = 0;
                                        foreach($fpi as $gam){
                                            $x++;
                                            if($this->upload->do_upload($gam)){
                                                //Get Filename
                                                $fnm = $this->upload->data('file_name');
                                                chmod('./asset/sdpic/'.$fnm, 0777);
                                                //Update user table on "Photo" column where Mail as ID
                                                $this->loginm->upvo(array('by_user' => $mail), array('kode' => $kod), array('photo' => $fnm));
                                            }else{
                                                $errmsg[] = array('ico' => 'ti-info', 'txt' => "<b>Info: Photo $x</b><br><i> :: ".$this->upload->display_errors().'</b>',
                                                    'typ' => 'warning');
                                            }
                                        }
                                    }else{
                                        $errmsg[] = array('ico' => 'ti-info', 'txt' => "<b>Info: </b<i>No Detail Pitcures Selected</i>",
                                                    'typ' => 'warning');
                                    }
$config['upload_path']='。/asset/sopic/';//在“sopic”上传上
$config['allowed_types']=“jfif | jpg | jpeg | png | gif”;//仅限Pitcure
$config['max_size']='2048';//2MB
$config['encrypt_name']=TRUE;
//$config['file_name']=$prna;//设置新名称
$this->load->library('upload',$config);//加载库上载
$id=$this->loginm->getshopid(数组(“nama”=>$nam)、数组(“exp”=>$dat));
//检测到照片正常
如果($this->upload->do_upload('foto')){
//获取文件名
$fnm=$this->upload->data('file_name');
chmod('./资产/sopic/'.$fnm,0777);
//更新“照片”列上的用户表,其中邮件作为ID
$this->loginm->upvo(阵列('by_user'=>$mail)、阵列('kode'=>$kod)、阵列('photo'=>$fnm));
$errmsg[]=array('ico'=>'ti check','txt'=>'OK:Shop Photo
。$tus.'added!', “typ”=>“success”); }否则{ $errmsg[]=array('ico'=>'ti info','txt'=>'info:
。$this->upload->display_errors()。', “典型”=>“警告”); } 如果(!空($fpi)){ $x=0; 外汇($fpi作为$gam){ $x++; 如果($this->upload->do_upload($gam)){ //获取文件名 $fnm=$this->upload->data('file_name'); chmod('./资产/sdpic/'.$fnm,0777); //更新“照片”列上的用户表,其中邮件作为ID $this->loginm->upvo(阵列('by_user'=>$mail)、阵列('kode'=>$kod)、阵列('photo'=>$fnm)); }否则{ $errmsg[]=array('ico'=>'ti info','txt'=>“信息:照片$x
:”“$this->upload->display_errors()”, “典型”=>“警告”); } } }否则{
$errmsg[]=array('ico'=>'ti info','txt'=>“info:使用以下命令更改foreach循环代码

    $files = $_FILES['file'];
    if(!empty($files['name'])){
        foreach($_FILES['file']['name'] as $key => $gam){
            $_FILES['images[]']['name']= $files['name'][$key];
            $_FILES['images[]']['type']= $files['type'][$key];
            $_FILES['images[]']['tmp_name']= $files['tmp_name'][$key];
            $_FILES['images[]']['error']= $files['error'][$key];
            $_FILES['images[]']['size']= $files['size'][$key];
            if($this->upload->do_upload('images[]')){
                //Get Filename
                $fnm = $this->upload->data('file_name');
                chmod('./asset/sdpic/'.$fnm, 0777);
                //Update user table on "Photo" column where Mail as ID
                $this->loginm->upvo(array('by_user' => $mail), array('kode' => $kod), array('photo' => $fnm));
            }else{
                $errmsg[] = array('ico' => 'ti-info', 'txt' => "<b>Info: Photo $x</b><br><i> :: ".$this->upload->display_errors().'</b>',
                    'typ' => 'warning');
            }
        }
    }else{
        $errmsg[] = array('ico' => 'ti-info', 'txt' => "<b>Info: </b<i>No Detail Pitcures Selected</i>",
                    'typ' => 'warning');
    }
$files=$\u文件['file'];
如果(!empty($files['name'])){
foreach($_FILES['file']['name']作为$key=>$gam){
$_FILES['images[]]['name']=$FILES['name'][$key];
$_FILES['images[]]['type']=$FILES['type'][$key];
$\u FILES['images[]]['tmp\u name']=$FILES['tmp\u name'][$key];
$_FILES['images[]]['error']=$FILES['error'][$key];
$_FILES['images[]]['size']=$FILES['size'][$key];
如果($this->upload->do_upload('images[])){
//获取文件名
$fnm=$this->upload->data('file_name');
chmod('./资产/sdpic/'.$fnm,0777);
//更新“照片”列上的用户表,其中邮件作为ID
$this->loginm->upvo(阵列('by_user'=>$mail)、阵列('kode'=>$kod)、阵列('photo'=>$fnm));
}否则{
$errmsg[]=array('ico'=>'ti info','txt'=>“信息:照片$x
:”“$this->upload->display_errors()”, “典型”=>“警告”); } } }否则{
$errmsg[]=array('ico'=>'ti info','txt'=>“信息:$fpi数组中有什么?$fpi来自文件$fpi=$this->input->post(“文件”,TRUE);变量$key来自什么?
    $files = $_FILES['file'];
    if(!empty($files['name'])){
        foreach($_FILES['file']['name'] as $key => $gam){
            $_FILES['images[]']['name']= $files['name'][$key];
            $_FILES['images[]']['type']= $files['type'][$key];
            $_FILES['images[]']['tmp_name']= $files['tmp_name'][$key];
            $_FILES['images[]']['error']= $files['error'][$key];
            $_FILES['images[]']['size']= $files['size'][$key];
            if($this->upload->do_upload('images[]')){
                //Get Filename
                $fnm = $this->upload->data('file_name');
                chmod('./asset/sdpic/'.$fnm, 0777);
                //Update user table on "Photo" column where Mail as ID
                $this->loginm->upvo(array('by_user' => $mail), array('kode' => $kod), array('photo' => $fnm));
            }else{
                $errmsg[] = array('ico' => 'ti-info', 'txt' => "<b>Info: Photo $x</b><br><i> :: ".$this->upload->display_errors().'</b>',
                    'typ' => 'warning');
            }
        }
    }else{
        $errmsg[] = array('ico' => 'ti-info', 'txt' => "<b>Info: </b<i>No Detail Pitcures Selected</i>",
                    'typ' => 'warning');
    }