在codeigniter中上传图片

时间:2015-04-07 12:20:34

标签: codeigniter

我正在尝试上传图片,我也想在数据库中插入文件名。代码应该在codeigniter中。请帮我。我试过这段代码。 控制器:

function insert()
{

    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '1000';
    $config['max_width'] = '1024';
    $config['max_height'] = '768';

    $this->load->library('upload', $config);

    if (!$this->upload->do_upload()) {
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('uploadv', $error);
    } else {
        $data = $this->upload->data();
        $iname = $data['file_name'];

        $name = $this->input->post('name');
        $age = $this->input->post('age');
        $this->Exam_mod->insert($name, $age, $img);
    }
}

1 个答案:

答案 0 :(得分:0)

试试这个

$this->Exam_mod->insert($name, $age, $iname);