Welcome Guest, Not a member yet? Register   Sign In
Send File by Email through Form on Web Site?
#11

[eluser]invision[/eluser]
Can anyone help me out with this?


Thanks again
#12

[eluser]eoinmcg[/eluser]
the error message is pretty self explanatory.

you're calling the apply method but not supplying $slug

i see from your view that slug is posted from the form, rather than passed by url.

Code:
function apply()
{

  $slug = $this->input->post('slug');
#13

[eluser]invision[/eluser]
OK, I think I'm getting there.

It submits and sends the email, but doesn't attach the file.


When I submit the form I get this message on the page:

Code:
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!


My Controller:

Code:
function apply(){
  
    $slug = $this->input->post('slug');
  
    $data['page_data'] = $this->MPages->getPageBySlug('vacancies');
    //$data['page_data'] = $this->MVacancies->getVacancyItem($slug);
    //$data['page_data'] or redirect('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);
        }
    }


Thanks again for all your help, I think we're nearly there.
#14

[eluser]invision[/eluser]
Hi Eoin, could you possibly take another final look at this?

Really appreciate the help so far, but I'm super stuck with this.


Thanks again
#15

[eluser]eoinmcg[/eluser]
have you tried debugging it yourself?

nobody is going to write your code for you. the best way to learn is break the problem down into small steps. and lots of coffee

read your code carefully, read through the excellent user guide and search the forums - these problems have been solved many, many, times here.

good luck!
#16

[eluser]invision[/eluser]
Sounds good to me.

I'm just always a little bit nervous with it, but I suppose, what's the worst that can happen.

I'll be back when I make some progress Smile
#17

[eluser]invision[/eluser]
Starting to break it down, I notice I'm getting an issue here.

It's definitely storing the file name in $_FILES['file']['name'];

It seems to be this spot here: $file_name = $this->do_upload(); where it goes wrong.

The whole do_upload part just doesn't seem to want to play ball. I've tried the Upload demos on the server and it works great.


Any ideas?
#18

[eluser]invision[/eluser]
Nope, no idea what I'm doing here, any help you can give is greatly appreciated at this hair-tearing stage.
#19

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...ading.html

Quote:$this->upload->do_upload()

Performs the upload based on the preferences you've set. Note: By default the upload routine expects the file to come from a form field called userfile, and the form must be a "multipart type:

<form method="post" action="some_action" enctype="multipart/form-data" />
If you would like to set your own field name simply pass its value to the do_upload function:

$field_name = "some_field_name";
$this->upload->do_upload($field_name)
#20

[eluser]invision[/eluser]
Thanks for this.

I actually changed it to userfile an hour or so ago. But now I'm getting a stack of errors Sad

Bit gutted.




Theme © iAndrew 2016 - Forum software by © MyBB