0

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'));
}

My View :

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

The files was uploaded but the name file upload only in variable $name_file_doc. All file was uploaded but only the name is of the name $name_file_doc. Please help me

  • refer https://stackoverflow.com/a/40778817/6309457 – Devsi Odedra Dec 06 '19 at 04:29
  • Does this answer your question? [Multiple image upload with CodeIgniter](https://stackoverflow.com/questions/40778683/multiple-image-upload-with-codeigniter) – Dev Dec 06 '19 at 06:06
  • The all files was uploaded, but the all the namefiles is doc-date('YmdHis') not foto = foto-date('YmdHis') and doc = doc-date('YmdHis') – Genta Haetami Putra Dec 06 '19 at 06:30

1 Answers1

0

Use this:

  if(isset($_FILES['foto']['name'])){
             //write only foto file upload code here.
  }
  if(isset($_FILES['doc']['name'])){
             //write only doc file upload code here.
  }
janisz
  • 6,292
  • 4
  • 37
  • 70