Welcome Guest, Not a member yet? Register   Sign In
Upload File form and Email Attachment
#1

[eluser]invision[/eluser]
Hi,

I have a Vacancy on my web site and I'd like users to upload a CV and submit.
The File and Vacancy ID should be emailed when submitted.

However, I'm having some issues with my scripts and wonder if I could get some help?

Controller
Code:
function apply(){
  
    $slug = $this->input->post('slug');
  
    $data['page_data'] = $this->MPages->getPageBySlug('vacancies');
    
    $data['title'] = $data['page_data']['title'];
    $data['body'] = $data['page_data']['body'];
    
      if(isset($_FILES['file']['name'])) {
      
              $email = '[email protected]';
              
        $file_name = $this->do_upload(); // _do_upload() should return the path and name of the uploaded file
        $this->email->attach($file_name);
        
              $message = "$email has applied for this job.";
              $this->email->from($email, '[email protected]');
              $this->email->to('[email protected]');
              
              $this->email->subject('Application for Job #' . $id);
              $this->email->message($message);
              
              $this->email->send();
              
              $this->load->view('form_success');
              
          } else {
          
        $data['main'] = 'vacancies_apply';
        $this->load->vars($data);    
        $this->load->view('template');
        
      }
    
  }
  
  function do_upload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            
            $this->load->view('upload_form', $error);
        }    
        else
        {
            $data = array('upload_data' => $this->upload->data());
            
            $this->load->view('upload_success', $data);
        }
    }

View
Code:
<?php
echo auto_typography($title);
echo auto_typography($body);
?>  
  <?php echo $this->validation->error_string; ?>
  <?php echo form_open_multipart('vacancies/apply/'); ?>
  <p><label>File</label>&lt;input type="file" name="file" /&gt;&lt;/p>

  &lt;?php echo form_hidden('slug',$post['slug']); ?&gt;
  &lt;?php echo form_submit('submit', 'Submit'); ?&gt;
  &lt;?php echo form_close(); ?&gt;

When I first visit the page I get this error:


A PHP Error was encountered
Severity: Notice

Message: Undefined variable: post

Filename: views/vacancies_apply.php

Line Number: 9


And when I Submit the form (the email does send but with no File attached or Vacancy ID in place) I get this error:


A PHP Error was encountered

Severity: Notice

Message: Undefined variable: id

Filename: controllers/vacancies.php

Line Number: 60

You did not select a file to upload.




success!



I would really love some help with this.


Thanks for any pointers you can give.
#2

[eluser]Brad K Morse[/eluser]
Had the same problem, better late than never:

replace

Code:
$this->email->attach($file_name);

with

Code:
$this->email->attach($data['upload_data']['file_path'].$data['upload_data']['file_name']);




Theme © iAndrew 2016 - Forum software by © MyBB