Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

php - Codeigniters do_upload() function is not working

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...