[eluser]RaGe10940[/eluser]
Code:
function sendemail() {
$this->load->library('form_validation');
$anum = $this->input->post('anum');
$first = $this->input->post('fname');
$last = $this->input->post('lname');
if ((empty($anum)) || (empty($first)) || (empty($last))) {
$this->session->set_flashdata('emailview', 'You Must Use A Number, First Name And Last Name To Find Student');
redirect('email_controller/emailview', 'location');
} else {
$this->form_validation->set_rules('anum', 'A Number', 'required|alpha_numeric|exact_length[9]');
$this->form_validation->set_rules('fname', 'First Name', 'required|alpha|max_length[20]');
$this->form_validation->set_rules('lname', 'Last Name', 'required|alpha|max_length[20]');
$this->form_validation->set_rules('subject', 'Subject', 'max_length[30]|min_length[5]|required');
$this->form_validation->set_rules('message', 'Message', 'max_length[200]|min_length[5]');
if ($this->form_validation->run() == FALSE) {
$this->emailview();
} else {
$this->load->model('email_model');
$anum = $this->input->post('anum');
$first = $this->input->post('fname');
$last = $this->input->post('lname');
if ($this->email_model->checkstudent($anum, $first, $last)) {
$config['upload_path'] = '/usr/local/var/www/Test/ci/uploads/';
$config['allowed_types'] = 'txt|pdf';
$config['overwrite'] = TRUE;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
foreach ($_FILES as $key => $value) {
var_dump($value);
if (!$this->upload->do_upload($key)) {
$data['main_content'] = 'emailsystem/emails_view';
$data['error'] = $this->upload->display_errors('<p class="error">', '</p>');
$this->load->view('includes/no_js/template', $data);
} else {
$return = $this->upload->data();
$this->load->library('email');
$this->load->library('encrypt');
$anum = $this->input->post('anum');
$first = $this->input->post('fname');
$last = $this->input->post('lname');
$email = $this->email_model->emails($anum, $first, $last);
$subject = $this->input->post('subject');
$body = $this->input->post('message');
$file = $return['full_path'];
$this->email->from('[email protected]');
$this->email->to($email);
$this->email->subject($subject);
$this->email->message($body);
$this->email->attach($file);
if (!$this->email->send()) {
$this->emailview();
} else {
$this->session->set_flashdata('emailview', 'Email Sent To ' . $email . '. With A Number ' . $anum . '');
redirect('email_controller/emailview', 'location');
}
}
}
} else {
$data['main_content'] = 'emailsystem/emails_view';
$data['error'] = '<p class="error">Student With A Number ' . $anum . ' Does Not Exist</p>';
$this->load->view('includes/no_js/template', $data);
}
}
}
}
with the current controller, and this view :
<div id="attachment">
<input type="file" name="userfile[]" multiple="" />
</div>
I keep getting this error : You did not select a file to upload.
I do though however get this when I dump $value :
Code:
rray(5) { ["name"]=> array(2) { [0]=> string(8) "test.txt" [1]=> string(9) "test2.txt" } ["type"]=> array(2) { [0]=> string(10) "text/plain" [1]=> string(10) "text/plain" } ["tmp_name"]=> array(2) { [0]=> string(14) "/tmp/phpG4y0OF" [1]=> string(14) "/tmp/phpoG9lSJ" } ["error"]=> array(2) { [0]=> int(0) [1]=> int(0) } ["size"]=> array(2) { [0]=> int(11) [1]=> int(13) } }
both files are now in the array