Я использую эту библиотеку для мультизагрузки https://github.com/stvnthomas/CodeIgniter-Multi-Upload
Проблема: Мой код работает нормально, когда я выбираю все вложения по одному, но всякий раз, когда я выбираю несколько вложений по одномуодин он загружает только последний, игнорируя другие файлы.
вот мой код:
HTML
<div class="card-body">
<?php $attributes = array('name' => 'send_mail_today_interviews', 'id' => 'xin-form', 'autocomplete' => 'off');?>
<?php $hidden = array('user_id' => $session['user_id']);?>
<?php echo form_open_multipart('admin/send_mail/send_mail_today_interviews', $attributes, $hidden);?>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="from_email">From </label>
<input type="text" class="form-control" name="from_email" value="<?php echo $session["email"] ?>">
</div>
</div>
<!-- <div class="col-md-6">
<div class="form-group">
<label for="to_email">To (Separate multiple emails by comma)</label>
<input type="text" class="form-control" value="kamal@i2k2.com" name="to_email">
</div>
</div> -->
<div class="col-md-4">
<div class="form-group">
<label for="to_email">To </label>
<select multiple class="form-control" name="to_email[]" data-plugin="select_hrm" data-placeholder="<?php echo $this->lang->line('dashboard_employees');?>">
<option value=""></option>
<?php foreach($all_employees as $employee) {?>
<option value="<?php echo $employee->email;?>" <?php if($employee->email=="kamal@i2k2.com"):?> selected="selected"<?php endif;?> ><?php echo $employee->first_name. ' ' .$employee->last_name;?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="subject">Subject</label>
<input type="text" class="form-control" name="subject" value="Interview Schedule Today || <?php echo $this->Xin_model->set_date_format(date("Y-m-d")) ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="resume">Attachment</label>
<span class="btn btn-primary btn-file"> <?php echo $this->lang->line('xin_browse');?>
<input type="file" name="attachment" multiple="" id="attachment">
</span>
<?php if($system_setting[0]->job_application_format!=''){?>
<br>
<small>Allowed Files: <?php echo $system_setting[0]->job_application_format;?></small>
<?php } ?>
<br>
<span id="sel_files"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="description">Message</label>
<textarea class="form-control textarea" placeholder="Message" name="message" cols="30" rows="15" id="message"><?php echo $message ?></textarea>
</div>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary"> <i class="fa fa-check-square-o"></i> Send </button>
</div>
<?php echo form_close(); ?>
</div>
Код для загрузки файла
if(!empty($_FILES['attachments']['name'])){
//Upload file
$config['upload_path'] = './uploads/attachments/';
$config['allowed_types'] = 'gif|jpg|png|JPG|jpeg|pdf|doc|docx|xlsx|csv|txt';
$this->load->library('upload', $config);
// Multi upload
if (!$this->upload->do_multi_upload('attachments')){
$Return['error'] = $this->upload->display_errors();
}
// if ( ! $this->upload->do_upload('attachments'))
// {
// $Return['error'] = $this->upload->display_errors();
// }
}
if($Return['error']!=''){
$this->output($Return);
exit;
}