Welcome Guest, Not a member yet? Register   Sign In
Empty file upload field
#1

[eluser]tj530[/eluser]
Currently, i can hit upload in my form without choosing a file and it will still run the code. I tried adding code so that my code would stop if there is no file chosen to upload but it wont work. Can someone please help me with this.


MY FUNCTION
Code:
function upload_image($field = 'userfile')
    {
        // this was the code that was supposed to check to see if there was any file chosen but it doesnt work at all. the code still runs even when no file is chosen...
        if ( ! isset($_FILES[$field])){
        return FALSE;
        } else {
            
            if ($this->input->post('upload')) {
                $userid = $this->session->userdata('userid');
                
                $user_row = $this->users_model->get_user_info($userid);
                    $old_image = $user_row->image_path;
                    
                    if ($old_image != 'default_image_small.png') {
                        
                        $thumbfilename = SITEPATH.'images/thumbs/'.$old_image;
                        if (file_exists($thumbfilename)) {
                            unlink($thumbfilename);
                        }    
                        $filename = SITEPATH.'images/'.$old_image;
                        if (file_exists($filename)) {
                            unlink($filename);
                        }
                    }
                    
                $this->images_model->do_upload($userid);
                $user_row = $this->users_model->get_user_info($userid);
                $success = "Your image was successfully uploaded";
                $data = array(
                    'menu tab' => 'home',
                    'user_row' => $user_row,
                    'success' => $success
                    );
                $this->load->view('users/user_success', $data);
            }
        }
    }

My View
Code:
<?php
echo form_open_multipart('user/upload_image');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();
?>

My Model
Code:
function do_upload($userid) {
        
        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path' => $this->image_path,
            'max_size' => 2000
        );
        
        
        
        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $image_data = $this->upload->data();
        $config = array(
            'source_image' => $image_data['full_path'],
            'new_image' => $this->image_path . '/thumbs',
            'maintain_ration' => true,
            'width' => 75,
            'height' => 75
        );
        
        $this->load->library('image_lib', $config);
        $this->image_lib->resize();
        
        $update_image = $image_data['file_name'];
        $new_image_data = array(
            'image_path' => $update_image
        );
        
        $this->db->where('id', $userid);
        $this->db->update('users', $new_image_data);
    }
}


Messages In This Thread
Empty file upload field - by El Forum - 12-27-2010, 11:19 AM
Empty file upload field - by El Forum - 12-27-2010, 11:28 AM
Empty file upload field - by El Forum - 12-27-2010, 11:44 AM
Empty file upload field - by El Forum - 12-27-2010, 11:46 AM
Empty file upload field - by El Forum - 12-27-2010, 11:49 AM
Empty file upload field - by El Forum - 12-27-2010, 01:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB