【发布时间】:2019-03-20 14:07:09
【问题描述】:
我想上传带有 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');
}
但我尝试上传时总是显示错误“文件不支持”。
【问题讨论】:
-
$fpi 数组中有什么?
-
$fpi 来自文件 $fpi = $this->input->post("file", TRUE);
标签: php html arrays codeigniter upload