簡體   English   中英

表中的CodeIgniter和圖像顯示

[英]CodeIgniter And Image Display in Table

我正在使用codeIgniter並將圖像路徑與表單數據一起上傳到數據庫中。 我面臨的問題是它們沒有顯示在表中。 圖像已成功上載到文件夾中,並且路徑也保存在db中,但未顯示圖像。 我寫的代碼如下。 在視圖文件中:

<?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();
}

最后是模型:public function insert(){

    $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');

    }

嘗試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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM