My Controller :
$foto = $_FILES['foto']['name'];
$doc = $_FILES['doc']['name'];
$ambextFoto = explode(".",$foto);
$ambextDOc = explode(".",$doc);
$ekstensiFoto = end($ambextFoto);
$ekstensiDoc = end($ambextDoc);
$nama_baru_foto = 'foto-'.date('YmdHis');
$nama_baru_doc = 'doc-'.date('YmdHis');
$nama_file_foto = $nama_baru_foto.".".$ekstensiFoto;
$nama_file_doc = $nama_baru_doc.".".$ekstensiDoc;
$config['upload_path'] = './assets/userfiles/usulan/';
$config['allowed_types'] = 'pdf';
$config['file_name'] = $nama_file_foto;
$config['file_name'] = $nama_file_doc;
$this->upload->initialize($config);
if($this->upload->do_upload('foto') AND $this->upload->do_upload('doc')){
$data = array(
'member_id' => $this->session->userdata('member_id'),
'foto' => $foto,
'doc' => $doc
);
}else{
$this->session->set_flashdata('error','Upload File Failed');
redirect(site_url('data/usulan/add'));
}
我的观点 :
<form action="<?php echo site_url('data/usulan/insert') ?>" method="post" enctype="multipart/form-data">
<div class="form-group">
<input type="file" class="form-control" name="foto" accept="application/pdf">
</div>
<div class="form-group">
<input type="file" class="form-control" name="doc" accept="application/pdf">
</div>
<div class="card-footer text-right">
<button type="submit" class="btn btn-primary ml-auto">Submit</button>
</div>
</form>
文件已上传,但名称文件仅在变量 $name_file_doc 中上传。所有文件都已上传,但只有名称为 $name_file_doc。 请帮助我
使用这个:
if(isset($_FILES['foto']['name'])){
//write only foto file upload code here.
}
if(isset($_FILES['doc']['name'])){
//write only doc file upload code here.
}