简体   繁体   English

表中的CodeIgniter和图像显示

[英]CodeIgniter And Image Display in Table

I'm using codeIgniter and uploading image path along with form data in database. 我正在使用codeIgniter并将图像路径与表单数据一起上传到数据库中。 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. 图像已成功上载到文件夹中,并且路径也保存在db中,但未显示图像。 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() { 最后是模型: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');

    }

try print_r($file_data) and see what comes back, you can also try: $file_data['orig_name'] 尝试print_r($file_data)看看会回来什么,您也可以尝试: $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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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