View File:
<div class="form-group">
<input type="file" name="file[]">
<button type="submit" class="btn btn-success">Add New Record</button>
</div>
Controller File:
$path = './files';
$ckdir = is_dir ( $path );
if (! $ckdir) {
mkdir ( $path, 0777, true );
}
$countfiles = count ( $_FILES ['files'] ['name'] );
// Looping all files
for($i = 0; $i < $countfiles; $i ++) {
if (! empty ( $_FILES ['files'] ['name'] [$i] )) {
// Define new $_FILES array - $_FILES['file']
$_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];
// Set preference
$config ['upload_path'] = $path;
$config ['allowed_types'] = '*';
$config ['file_name'] = $_FILES ['files'] ['name'] [$i];
// Load upload library
$this->load->library ( 'upload', $config );
// File upload
if ($this->upload->do_upload ( 'file' )) {
// Get data about the file
$uploadData = $this->upload->data ();
$filename = $uploadData ['file_name'];
// Initialize array
$data ['filenames'] [] = $filename;
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…