无法通过图片上传插入数据

时间:2016-08-12 04:31:13

标签: php codeigniter codeigniter-3

当运行成功时,我将插入数据沿上传图像插入数据库,但插入数据和上传图像时包含错误。

  

图像的路径不正确。

     

您的服务器不支持处理此类图像所需的GD功能。

如果我在没有上传图片的情况下插入数据怎么处理不是错误?并且图像数据库进入默认图像?

这是我的控制器

public function save(){   
    $this->load->library('image_lib');
    //$nama_asli = $_FILES['userfile']['name'];
    $id = $this->input->post('id',TRUE);

    $config['file_name'] = $id ;//'_'.'_'.$nama_asli;
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
    $config['max_size'] = '100000';

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

    $this->upload->initialize($config);
    if ( ! $this->upload->do_upload('userfile'))
    {
        $files = $this->upload->data();
        $fileNameResize = $config['upload_path'].$config['file_name'];
        $size =  array(             
                    array('name'    => 'thumb','width'  => 100, 'height'    => 100, 'quality'   => '100%')
                );
        $resize = array();
        foreach($size as $r){               
            $resize = array(
                "width"         => $r['width'],
                "height"        => $r['height'],
                "quality"       => $r['quality'],
                "source_image"  => $fileNameResize,
                "new_image"     => $url.$r['name'].'/'.$config['file_name']
            );
        $this->image_lib->initialize($resize); 
            if(!$this->image_lib->resize())                 
            die($this->image_lib->display_errors());
        }   

    }
    else
    {
        $data = array('upload_data' => $this->upload->data());      
        $get_name = $this->upload->data();
        $nama_foto = $get_name['file_name'];
        $this->mcrud->savealat($nama_foto);
        redirect('instrument/detailalat');      
    }
}   

这是我的模特

function savealat($nama_foto) {
    $data = array(
        'id' => $this->input->post('id'),
        'namaalat' => $this->input->post('namaalat'),
        'dayalistrik' => $this->input->post('dayalistrik'),     
        'merk' => $this->input->post('merk'),
        'namasupplier' => $this->input->post('namasupplier'),       
        'nokatalog' => $this->input->post('nokatalog'),     
        'noseri' => $this->input->post('noseri'),       
        'category' => $this->input->post('category'),
        'lokasi' => $this->input->post('lokasi'),
        'pengguna' => $this->input->post('pengguna'),
        'status' => $this->input->post('status'),
        'jadwalkal' => $this->input->post('jadwalkal'),     
        'manual' => $this->input->post('manual'),
        'dateinput' => $this->input->post('date'),      
        'foto' => $nama_foto
        //'created' => $tanggal
    );  
    $this->db->insert('tbdetail', $data);
}   

2 个答案:

答案 0 :(得分:1)

{{1}}

如果我是对的,问题是你把上传放在其他地方。尝试移动代码并告诉我它是否有效

答案 1 :(得分:1)

妈妈,这个答案可以帮到你。在评论部分有更多的建议可以为你找出一些出路。 Your server does not support the GD function required to process this type of image.Ci