简体   繁体   中英

CodeIgniter And Image Display in Table

I'm using codeIgniter and uploading image path along with form data in database. The problem that i'm facing is they're not displaying in table. Images are successfully uploaded in the folder and the path is also saved in db but it's not displaying the images. Code that i've written is below. In view file:

<?php echo form_open_multipart('welcome/insertion'); ?>
<input type="file" name="userfile" id="userfile" size="40" maxlength="90" tabindex="3"/>
<input name="saveForm" type="submit" value="Insert Record" class="iconSave" />

In controller i write:

public function insertion()
{
    $this->load->model('data_maintenance','',TRUE);
    $this->data_maintenance->insertion();
}

And finally in model: public function insertion() {

    $config['upload_path'] = 'application/uploads';
    $config['allowed_types'] = 'gif|jpg|jpeg|png|pdf';
    $config['max_size'] = '5000';
    $this->load->library('upload', $config);
    $this->upload->initialize($config);
    if ( ! $this->upload->do_upload('userfile'))
    {
        echo $this->upload->display_errors();


    }
    else
    {
        //$file_data  =   $this->upload->data('image');
        $file_data = $this->upload->data();

        $new_staff = array(
                'agenda_id' => $this->input->post('agenda_id'),
                't_name' => $this->input->post('t_name'),
                'exp' => $this->input->post('exp'),
                'leaves_allow_monthly' => $this->input->post('leaves_allow_monthly'),
                'leaves_allow_annualy' => $this->input->post('leaves_allow_annualy'),
                'gender' => $this->input->post('gender'),
                'cell_no' => $this->input->post('cell_no'),
                'dob' => $this->input->post('dob'),
                'file' => $file_data['file_name']

        );


    }
    $d="/SampleOOP/application/uploads/" . $new_staff['file'];
    $this->db->set('image', $d);
    //$this->db->insert('teachers_record');


    //$d="/SampleOOP/application/uploads/".$new_staff['file'];
    $this->db->set('teacher_name', $new_staff['t_name']);
    //$this->db->set('image',$d);
    $this->db->insert('teachers_record');

    }

try print_r($file_data) and see what comes back, you can also try: $file_data['orig_name']

Or:

$file_name = $file_data['file_name'];

$new_staff = array(
        'agenda_id' => $this->input->post('agenda_id'),
        't_name' => $this->input->post('t_name'),
        'exp' => $this->input->post('exp'),
        'leaves_allow_monthly' => $this->input->post('leaves_allow_monthly'),
        'leaves_allow_annualy' => $this->input->post('leaves_allow_annualy'),
        'gender' => $this->input->post('gender'),
        'cell_no' => $this->input->post('cell_no'),
        'dob' => $this->input->post('dob'),
        'file' => $file_name

);

UPDATE, Try:

$config['upload_path'] = 'application/uploads';
$config['allowed_types'] = 'gif|jpg|jpeg|png|pdf';
$config['max_size'] = '5000';
$this->load->library('upload', $config);

Or

$this->load->library('upload');
$config['upload_path'] = 'application/uploads';
$config['allowed_types'] = 'gif|jpg|jpeg|png|pdf';
$config['max_size'] = '5000';
$this->upload->initialize($config);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM