Welcome Guest, Not a member yet? Register   Sign In
Uploading Multiple Files As Email Attachment
#7

[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">
&lt;input type="file" name="userfile[]" multiple="" /&gt;
</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


Messages In This Thread
Uploading Multiple Files As Email Attachment - by El Forum - 03-28-2013, 07:39 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-28-2013, 08:08 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-28-2013, 08:24 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-28-2013, 08:33 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-28-2013, 08:34 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-28-2013, 08:38 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-28-2013, 08:48 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-28-2013, 08:55 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-28-2013, 12:48 PM
Uploading Multiple Files As Email Attachment - by El Forum - 03-28-2013, 07:20 PM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 01:23 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 01:26 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 05:41 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 05:42 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 05:45 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 06:57 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 07:01 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 07:16 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 07:23 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 07:34 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 07:50 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 08:03 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 08:15 AM
Uploading Multiple Files As Email Attachment - by El Forum - 03-29-2013, 09:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB