Codeigniters do_upload() function is not working

江枫思渺然 提交于 2019-11-27 08:50:42

问题


If I remove the part $this->upload->do_upload('filefoto') my data is saved into the database, but the image file is not saved to the folder path.

enter link description here

Copied from pastebin

public function tambahanggota() {    
    $this->load->library('upload');
    $nmfile = "file_".time();
    $config['upload_path'] = './assets/uploads/';
    $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
    $config['max_size'] = '3072';
    $config['max_width']  = '5000';
    $config['max_height']  = '5000';
    $config['file_name'] = $nmfile;

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

    if($_FILES['filefoto']['tmp_name'])
    {
        if ($this->upload->do_upload('filefoto'))
        {
            $gbr = $this->upload->data();
            $data = array(

            'nm_gbr' =>$gbr['file_name']                
            );

            $res = $this->M_tambahdata->tambahdata("anggota",$data);

            $config2['image_library'] = 'gd2';
            $config2['source_image'] = $this->upload->upload_path.$this->upload->file_name;
            $config2['new_image'] = './assets/hasil_resize/';
            $config2['maintain_ratio'] = TRUE;
            $config2['width'] = 100;
            $config2['height'] = 100;
            $this->load->library('image_lib',$config2);

            if ($res>=1) {

            echo "<script>alert('Data berhasil disimpan')</script>";
            echo "<script>window.location='".base_url()."dataanggota'</script>";
            }

            else{
                $this->session->set_flashdata('pesan', 'Maaf, ulangi data gagal di inputkan.');
                redirect('dashboard/index');
            }

        }
    }
}

How can I upload my images?


回答1:


on a shared server hosting you may need to provide the complete relative path to your upload folder. Also make sure you have all permissions to write a file to that directory!

you can use on a localhost environment

$config['upload_path']   = './assets/upload'; 

but on a shared hosting, you'll need to get more specific, normally something like

$config['upload_path']   = '/home/yourserver/public_html/assets/upload'; 

You can find this upload_path, e.g. in your accounts cPanel main page on the left column or might want to call your provider's helpdesk for more info on the correct path.




回答2:


you missed this

$this->upload->upload_path.'/'.$this->upload->file_name;



来源:https://stackoverflow.com/questions/41596491/codeigniters-do-upload-function-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!