I have used codeigniter file uploading ,single and multiple both. but if the file names are not in an array how to upload files. ex:- if form1 has file1,file2 and file3 file-inputs, and user only providing file1 and file3. then how to identify if file2 is not given. if i use the array format, it is not possible to find which particular field is given and which is not.
I have tried array based uploading but, any file missing will give me a wrongly indexed array. I need to have a proper $_POST
where non selected form members are clearly given.
It will post only $_FILES
which have value.
HTML
<input type="file" name="mass_consume_upload[]" />
<input type="file" name="mass_consume_upload[]" />
<input type="file" name="mass_consume_upload[]" />
PHP (Codeigniter)
$this->load->library('upload');
$tempfiles = $_FILES;
//print_r($tempfiles);
foreach ($tempfiles as $files) {
$_FILES['mass_consume_upload'] = $files;
$this->upload->initialize(array(
'upload_path' => $path,
'allowed_types' => 'pdf',
'overwrite' => FALSE
));
if (!$this->upload->do_upload('mass_consume_upload')) {
$uploadArr['error'][] = array(
'filename' => $_FILES['mass_consume_upload']['name'],
'msg' => $this->upload->display_errors('', '')
);
} else {
$uploadArr['success'][] = array('filename' => $_FILES['mass_consume_upload']['name']);
}
}