【问题标题】:CodeIgniter my photo can't be inserted into databaseCodeIgniter 我的照片无法插入数据库
【发布时间】:2018-01-02 18:47:03
【问题描述】:

这是我的代码,我的照片无法插入数据库。不知道问题出在哪里。

控制器:

public function add_gambar()
    {
        $config['upload_path'] = './assets/img/';
        $config['allowed_types'] = 'jpg|png';
        $config['max_size'] = '2000';
        $config['max_width'] = '1024';
        $config['max_height'] = '768';

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

        if ( !$this->upload->do_upload('gambar'))
        {
            $this->Gambarhome_model->tambah_gambar_error();
           redirect('gambarhome/','refresh');
        }
        else
        {

            $this->Gambarhome_model->tambah_gambar();
            redirect('gambarhome/','refresh');
        }
    }

型号:

function tambah_gambar(){
        $date = $this->upload->data();
        $data=array(
        'judul'=>$this->input->post('judul'),
        'desc'=>$this->input->post('desc'),
        'gambar'=>$date['file_name']
        );
        $this->db->insert('gambarhome',$data);
    }

有人帮帮我,谢谢!

【问题讨论】:

    标签: php jquery mysql codeigniter codeigniter-3


    【解决方案1】:

    当你加载上传库时尝试使用这个:

    $this->upload->initialize($config);
    

    然后尝试上传带有if条件的图片。

    【讨论】:

      【解决方案2】:

      使用 BLOB 数据类型

      您使用什么数据类型将图像存储在数据库表中?使用 LONGBLOB 将二进制大对象存储到表中。如果要存储超过 1Mb 的图像文件,可以通过在服务器配置文件中进行必要的更改来实现。没用过 LONGBLOB 试试看。

      $config['upload_path'] = './assets/img/';
      //make sure that you have given the correct path
      

      【讨论】:

        猜你喜欢
        • 2017-10-23
        • 1970-01-01
        • 2017-10-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多