php - CodeIgniter 和表格中的图像显示

标签 php mysql eclipse codeigniter

我正在使用 codeIgniter 并上传图像路径以及数据库中的表单数据。我面临的问题是它们没有显示在表格中。图像已成功上传到文件夹中,路径也保存在数据库中,但不显示图像。 我写的代码如下。 在 View 文件中:

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

在 Controller 中我写:

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

最后在模型中: 公共(public)函数插入() {

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

关于php - CodeIgniter 和表格中的图像显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27024289/

相关文章:

mysql - Xampp MySQL 拒绝连接

java - 数据检索 - 带有 Eclipse 的 JDBC

php - 我的 PHP 代码是面向对象的吗?

php - 如何在连接表中设置 Laravel 的 Eloquent 关系?

mysql - mysql执行查询的顺序

eclipse - Ant &lt;input/> 不再在 Eclipse Helios 中工作 (3.6)

java - Eclipse 资源包编辑器(表格格式)?

php - Yii - findAll 排序依据

php - 有没有办法在 PHP 中执行 "forward trace"?

java - MySql 选择查询未正常运行