0

Whenever I choice file from browse and click upload, it does not work.

It is codeignitor project. I am new in php and codeignitor.

#My coctroller name is member and code is below:
public function profile_change_avater(){

    $this->load->model('member_model');

    if($this->input->post('upload'))
    {
        $this->member_model->do_upload();
    }
    $data['title'] = "Choise your Avater";
    echo "<pre>";
    print_r($data['title']);
    echo "</pre>";
$this->common_load_view('member/user_extended_profile_change_avater_content_view',
'members', 'profile_change_avater', $data );

}

My model name is member_model, code is below:

public function do_upload(){

    //$this->image_path = realpath(APPPATH .'../asset/images' );
    $this->upload->initialize($config);
    $config = array(
        'allowed_type' => 'jpg|jpeg|gif|png',
        'upload_path'  => 'image_path',     
        'max_size'     => '2000'
    );

    $this->load->library('upload', $config);
    $this->upload->do_upload();

    if( ! $this->upload->do_upload()){
        $error = array('error'=>$this->upload->display_error());
        return $error;
    }
    else 
    {
        $data = array('upload_data'=> $this->upload->data());
        return $data;
    }


}
 Here is the code view:
<p id="avatar-upload">
<?php   echo  form_open_multipart('member/profile_change_avater');
    echo form_upload('userfile');
    echo form_submit('upload','Upload');
     echo form_close();
     ?>
</p>

What's wrong in my code. If any body help me. It world be great.

1

2 Answers 2

1

in view

<p id="avatar-upload">
<?php   echo  form_open_multipart('member/profile_change_avater'); ?>
<input type="file" name='image'>
<?php    echo form_submit('upload','Upload');
     echo form_close();
     ?>
</p>

and change if condition of profile_change_avater()

if($this->input->post())
    {
        $config = array(

            'allowed_type' => 'jpg|jpeg|gif|png',
            'upload_path'  => 'image_path',     
            'max_size'     => '2000'
        );

        $this->load->library('upload', $config);


        if( ! $this->upload->do_upload('image')){
            $error = array('error'=>$this->upload->display_error());

        }
        else 
        {
            $data = array('upload_data'=> $this->upload->data());

        }

    }
Sign up to request clarification or add additional context in comments.

Comments

0

Controller

public function uesr_profile(){     
    if($this->input->post()){
        $config['tmp_name'] = $_FILES['userfile']['tmp_name'];
        $config['upload_path'] = './';
        $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
        $config['max_size'] = 1024 * 5;
        $config['max_width']  = 1024;
        $config['max_height']  = 768;   
        $config['file_name'] = $_FILES['userfile']['name'];

        $this->load->library('upload', $config);
        $this->upload->initialize($config);

        if (!$this->upload->do_upload()){
            $this->data['error'] =  $this->upload->display_errors();
        }
    }      
        $this->load->view('profile_page',$this->data);              
}

View

<?php echo form_open_multipart('users/uesr_profile'); ?>
<input type="file" name='userfile'>
<?php  echo form_submit('upload','Upload');
echo form_close(); ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.