1

Hi i'm trying to upload image to a folder and image name in database

in view

echo form_open_multipart('subscribers_c/actioncreate',array('class'=>'form'));`enter code here`
<input type='file' name='img'>

in controller

$config['upload_path'] ='./assets/uploads/subscribers_photos'; //The path where the image will be save
        $config['allowed_types'] = 'gif|jpg|png'; //Images extensions accepted
        $config['max_size']    = '2048'; 
        $config['max_width']  = '1024'; 
        $config['max_height']  = '768'; 
        $config['overwrite'] = TRUE; 
        $this->load->library('upload', $config); //Load the upload CI library
        if (!$this->upload->do_upload('img'))
        {
            $uploadError = array('upload_error' => $this->upload->display_errors()); 
            //$this->set_flashdata('msg_error', $uploadError, site_url().'/subscribers_c/actioncreate'); 
        }
        $file_info = $this->upload->data('img');
        $img_name = $file_info['file_name']; 

        $data=array(
            'chit_fund_id'=>$this->input->post('cid'),
            'first_name'=>$this->input->post('fname'),
            'last_name'=>$this->input->post('lname'),
            'dob'=>$this->input->post('bd'),
            'gender'=>$this->input->post('g'),
            'contact_number'=>$this->input->post('mob'),
            'address'=>$this->input->post('add'),
            'email_id'=>$this->input->post('eml'),
            'bid_status'=>$this->input->post('b_status'),
            'user_status'=>$this->input->post('u_status'),
            'image_name'=>$img_name,
        );
        //print_r($data);

image_name is not having any value how to get image name .

2
  • What does your form look like? Does it contain a enctype? Do you $_POST the image? That is something that doesn't work. Commented Sep 5, 2016 at 8:34
  • it is form_open_multipart() Commented Sep 5, 2016 at 8:40

3 Answers 3

3

Instead of img in upload data

$file_info = $this->upload->data('img');

Try

$file_info = $this->upload->data();
$img = $file_info['file_name']; 

And on here $config['upload_path'] = './assets/uploads/subscribers_photos'; end with /

Like $config['upload_path'] = './assets/uploads/subscribers_photos/';

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

4 Comments

i tried $img_name = $this->upload->data('file_name'); this is working fine.
$config['upload_path'] = './assets/uploads/subscribers_photos/'; this is not working my code is fine..
Is it not inserting into db is the image column name varchar 255
But I do not see where your insert function is for db on controller
1

Inside the view call the form_upload function(if needed, your one is also correct):

<?php echo form_upload('pic'); ?>  

Inside controller function for upload:

$img_name = $_FILES["pic"]["name"];  

By using this code you will get the file name.

Comments

1
$img_name = $this->upload->data('file_name'); 

1 Comment

Even if it could help, posting just a line of code isn't a good answer. Please have a look at How to Answer and add some explanation as at the moment it is a very low quality and will get deleted soon.

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.