codeigniter image uploading mysql

前端 未结 3 1237
忘了有多久
忘了有多久 2021-01-07 01:02

I wanted to know if I was uploading an image in CodeIgniter to a database what would be my

$config[\'upload_path\']

All the examples I have

3条回答
  •  [愿得一人]
    2021-01-07 01:06

    i posted here in hope this help someone since this is an old post and the answers are no help at all, this code works for me, also the model part is not here so you must figure it out reading codeigniter's docs , i think this will work if you put it in your controller, also it think the submit form must be pointing this function

    function upload() {
     $caption = $this->input->post('caption'); 
        $codigo = $this->input->post('codigo');
        //$imagen = $this->input->post('imagen');
        $config['upload_path'] = 'uploads';// this is a directory with 777 permissions where you upload the file
        $config['allowed_types'] = 'gif|jpg|jpeg|png|pdf';
        //$config['max_size'] = '5000';
        $this->load->library('upload', $config);
    
        if (!$this->upload->do_upload('imagen')) { // this is the input from the form
            echo $this->upload->display_errors();
        } else {
            //here $file_data receives an array that has all the info
            //pertaining to the upload, including 'file_name'
            $file_data = $this->upload->data();
    
            $fp = fopen($file_data['full_path'], 'r');
            $content = fread($fp, filesize($file_data['full_path']));
            //$content = addslashes($content);
            fclose($fp);
            $data = array( // this is the table i got in my db
                'idBotones' => null,
                'imagen' => $content, //blob image
                'caption' => $caption,
                'codigo' => $codigo
            );
    
            $this->load->model('generic_model');
            $table = "botones";
            $this->generic_model->insertar_datos($table, $data);
           //print_r($content);
        }
    }
    

提交回复
热议问题