Welcome Guest, Not a member yet? Register   Sign In
File Upload Error
#1

[eluser]Kemik[/eluser]
Hello,

Quote:Unable to find a post variable called userfile.

I get this error and I'm not sure why. The field is named userfile as requested in the user guide and the file uploads fine.

Controller
Code:
// Set avater config
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '50';
        $config['max_width'] = '100';
        $config['max_height'] = '100';

// Prepare form (already loaded url helper)
        $this->load->helper('form');
        $this->load->library('upload', $config);
        
        $field_name = "userfile";
        
        if ( ! $this->upload->do_upload($field_name)) {
            $data['error'] = $this->upload->display_errors();
        } else {
            $upload = $this->upload->data();
            
            // Update user
            $this->user_model->update_avater($upload, $this->session->userdata('user_id'));
            
            $data['uploaded'] = TRUE;
        }
View
Code:
<?=form_open_multipart('user/edit_avater'); ?>

<table border="0" cellpadding="3" cellspacing="1">

<tr>
    <td>Upload</td>
    <td>&lt;?= form_upload('userfile'); ?&gt;</td>    
</tr>

</table>

&lt;input type="submit" class="submit" value="Upload" /&gt;

&lt;?=form_close();?&gt;

Thanks.
#2

[eluser]ELRafael[/eluser]
If you use "userfile" as id/name of input, you can do like that

Code:
//See? No params in do_upload
if ($this->upload->do_upload())
{
  //bla bla bla
}

Try that
#3

[eluser]Kemik[/eluser]
Tried and still no difference.

The only reason I added the userfile to the function and declared the $field_name is because I got these errors and was trying to correct them.

No luck so far.




Theme © iAndrew 2016 - Forum software by © MyBB