我想上传带有 2 个输入文件的文件。 第一个输入仅输入 1 个文件,第二个输入多个文件。 第一个输入保存到"./asset/sopic",第二个保存到"./asset/SDPIC"。 这是我的代码(查看(:
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Photo</label>
<table frame="box">
<tr>
<td>
<img src="<?php echo base_url()."asset/sopic/default.png"; ?>" alt="..." id="foto" class="img-responsive center-block">
<input name="foto" type="file" class="form-control border-input" placeholder="Masukkan Gambar" accept="image/*" onchange="readURL(this);">
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label><span title="To select multiple image press 'CTRL' or 'SHIFT'." style="cursor: help;">Detailed Photo <i class="far fa-question-circle"></i></span></label>
<input type="file" name="file[]" class="form-control border-input" placeholder="Masukkan Gambar" accept="image/*" multiple>
</div>
</div>
这个模型:
$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');
}
但是我正在尝试上传总是显示错误"文件不支持"。
通过以下方式更改 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');
}