CodeIgniter和图像显示在表中

时间:2014-11-19 18:30:53

标签: php mysql eclipse codeigniter

我正在使用codeIgniter并将图像路径与表单数据一起上传到数据库中。我面临的问题是他们没有在桌子上展示。图像已成功上载到文件夹中,路径也保存在数据库中,但它不显示图像。 我写的代码如下。 在视图文件中:

<?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" />

在控制器中我写道:

public function insertion()
{
    $this->load->model('data_maintenance','',TRUE);
    $this->data_maintenance->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');

    }

1 个答案:

答案 0 :(得分:0)

尝试print_r($file_data)并查看返回的内容,您也可以尝试:$file_data['orig_name']

或者:

$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

);

更新,尝试:

$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);
相关问题