- Beranda
- Komunitas
- Tech
- Website, Webmaster, Webdeveloper
Multi Upload Pada Codeigniter
TS
nenisuryaniajah
Multi Upload Pada Codeigniter
ane mau berbagi cara multi upload pada codeigniter gan. semoga membantu
controller
function add() {
$data['tittle'] = 'Contoh Multi Upload pada codeigniter';
if ($_POST == NULL) {
show('upload_form', $data);
} else
$config['allowed_types'] = 'gif|jpg|png|pdf|doc|docx|bmp|jpeg';
$config['max_size'] = '5120';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['upload_path'] = './file/';
$this->load->library('upload', $config);
for ($i=1; $i<8; $i++) {
if ($this->upload->do_upload('userfile'.$i)) {
$error = array('error' => $this->upload->display_errors());
echo $error['error'];
} else {
$data = array('upload_data' => $this->upload->data());
$lokasi_file = $_FILES['userfile'.$i]['tmp_name'];
$tipe_file = $_FILES['userfile'.$i]['type'];
$nama_file1 = $_FILES['userfile1']['name'];
$nama_file2 = $_FILES['userfile2']['name'];
$nama_file3 = $_FILES['userfile3']['name'];
$nama_file4 = $_FILES['userfile4']['name'];
$nama_file5 = $_FILES['userfile5']['name'];
$nama_file6 = $_FILES['userfile6']['name'];
$nama_file7 = $_FILES['userfile7']['name'];
$vdir_upload = "file/";
$vfile_upload = $vdir_upload . $nama_file;
move_uploaded_file($_FILES["userfile".$i]["tmp_name"], $vfile_upload);
$upload = array(
'file 1' => $nama_file1,
''file 2' => $nama_file2,
''file 3' => $nama_file3,
''file 4' => $nama_file4,
''file 5' => $nama_file5,
''file 6' => $nama_file6,
'file 7' => $nama_file7
);
}
$this->Upload_model->add($upload);
echo "[removed]document.location.href = '../../index.php/upload' ;[removed]";
$this->session->set_flashdata('message', 'data berhasil disimpan';
redirect('[nama_class]';
}
}
}
view
<?php
for($i=0; $i<8; $i++){ ?>
<tr>
<td>Upload ke-<?php echo $i+1; ?>: </td>
<td><input type="file" name="userfile<?php echo $i; ?>"/></td>
</tr>
<?php
}
?>
controller
function add() {
$data['tittle'] = 'Contoh Multi Upload pada codeigniter';
if ($_POST == NULL) {
show('upload_form', $data);
} else
$config['allowed_types'] = 'gif|jpg|png|pdf|doc|docx|bmp|jpeg';
$config['max_size'] = '5120';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['upload_path'] = './file/';
$this->load->library('upload', $config);
for ($i=1; $i<8; $i++) {
if ($this->upload->do_upload('userfile'.$i)) {
$error = array('error' => $this->upload->display_errors());
echo $error['error'];
} else {
$data = array('upload_data' => $this->upload->data());
$lokasi_file = $_FILES['userfile'.$i]['tmp_name'];
$tipe_file = $_FILES['userfile'.$i]['type'];
$nama_file1 = $_FILES['userfile1']['name'];
$nama_file2 = $_FILES['userfile2']['name'];
$nama_file3 = $_FILES['userfile3']['name'];
$nama_file4 = $_FILES['userfile4']['name'];
$nama_file5 = $_FILES['userfile5']['name'];
$nama_file6 = $_FILES['userfile6']['name'];
$nama_file7 = $_FILES['userfile7']['name'];
$vdir_upload = "file/";
$vfile_upload = $vdir_upload . $nama_file;
move_uploaded_file($_FILES["userfile".$i]["tmp_name"], $vfile_upload);
$upload = array(
'file 1' => $nama_file1,
''file 2' => $nama_file2,
''file 3' => $nama_file3,
''file 4' => $nama_file4,
''file 5' => $nama_file5,
''file 6' => $nama_file6,
'file 7' => $nama_file7
);
}
$this->Upload_model->add($upload);
echo "[removed]document.location.href = '../../index.php/upload' ;[removed]";
$this->session->set_flashdata('message', 'data berhasil disimpan';
redirect('[nama_class]';
}
}
}
view
<?php
for($i=0; $i<8; $i++){ ?>
<tr>
<td>Upload ke-<?php echo $i+1; ?>: </td>
<td><input type="file" name="userfile<?php echo $i; ?>"/></td>
</tr>
<?php
}
?>
0
4.1K
11
Komentar yang asik ya
Urutan
Terbaru
Terlama
Komentar yang asik ya
Komunitas Pilihan