将文件数据和文本框,单选按钮值上传到数据库

时间:2014-03-27 12:48:13

标签: php forms codeigniter

我喜欢以该格式上传文件,其中包含一些文本框和一个文件上传按钮, 如何在codeigniter中执行此操作, 当我单独做到这一点我可以,但文件上传我不能

function upload()
{
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png|txt|pdf|doc|docx';
    $config['max_size'] = '1024';
    $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('js_home', $error);
    }
    else
    {
        $data = array('upload_data' => $this->upload->data(),'phone' =>$this->input->post('phone'),'email' =>$this->input->post('email'),'password' =>$this->input->post('password'));
        $this->jobseeker->storefile($data);
        $this->load->view('samples/upload_success', $data);// after uploaded the file
    }
}

1 个答案:

答案 0 :(得分:1)

试试这个

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

        $this->load->view('js_home', $error);
    }
    else
    {
 $fInfo = $this->upload->data(); 

        $data = array('upload_data' => $fInfo['file_name'],'phone' =>$this->input->post('phone'),'email' =>$this->input->post('email'),'password' =>$this->input->post('password'));
        $this->jobseeker->storefile($data);
        $this->load->view('samples/upload_success', $data);// after uploaded the file
    }

在视图<input type='file' name='file'>