Skip to content

Instantly share code, notes, and snippets.

@ngekoding
Created January 19, 2022 07:09
Show Gist options
  • Save ngekoding/50940056c8895c16516c3ee412d9285c to your computer and use it in GitHub Desktop.
Save ngekoding/50940056c8895c16516c3ee412d9285c to your computer and use it in GitHub Desktop.
Multiple file upload in CodeIgniter 3
<?php
$count = count($_FILES['files']['name']);
$successes = [];
$errors = [];
for ($i = 0; $i < $count; $i++) {
$_FILES['file']['name'] = $_FILES['files']['name'][$i];
$_FILES['file']['type'] = $_FILES['files']['type'][$i];
$_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
$_FILES['file']['error'] = $_FILES['files']['error'][$i];
$_FILES['file']['size'] = $_FILES['files']['size'][$i];
$config['upload_path'] = 'your/upload/path';
$config['remove_spaces'] = FALSE;
$config['allowed_types'] = 'pdf';
$config['max_size'] = 5120;
$this->load->library('upload',$config);
if ($this->upload->do_upload('file')){
$filename = $this->upload->data('file_name');
// handle your file
} else {
$errors[] = [
'filename' => $_FILES['file']['name'],
'error' => $this->upload->display_errors('', '')
];
}
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment