search

Home  >  Q&A  >  body text

Insert file size into database

I am uploading a file and the size remains as 0 in the database

$djenjang_capaian = $this->session->userdata('djenjang_capaian');
        $pengirim = $this->session->userdata('pengirim');
        
        $path = FCPATH. "/upload/document/capaian/$pengirim";
        
        if(!is_dir($path))
        {
            mkdir($path,0777,TRUE);
        }

        $config['upload_path'] = $path;
        $config['allowed_types'] = 'jpg|png|pdf|xlsx|xls|doc|docx|zip|rar';
        $config['max_size'] = "2048";
        $file_name = "dok-cpn-" . rand(100, 999) . uniqid();
        $config['file_name'] = $file_name;
        $this->load->library('upload', $config);
        $this->upload->do_upload('dokumen_file');
        $dokumen = $this->upload->data('file_name');
        $dokumen_file = $dokumen;
        $ukuran_file = $dokumen_file['size'];
        $data = array(
            'dokumen_file' => $dokumen_file,
            'ukuran_file' => $ukuran_file
        );
        if ($this->db->insert($djenjang_capaian, $data)) {
            $this->session->set_flashdata("success", " Data berhasil ditambahkan!");
            redirect('user/page/pemenuhan_dokumen');
        } else {
            $this->session->set_flashdata("error", " Data gagal ditambahkan!");
            redirect('user/page/pemenuhan_dokumen');
        }

This code runs fine but keeps inserting 0's on the ukuran_file field. How to insert file size into database? ...

P粉986860950P粉986860950443 days ago730

reply all(1)I'll reply

  • P粉248602298

    P粉2486022982023-09-14 00:43:34

    instead of

    $ukuran_file = $dokumen_file['size'];

    You must use

    $ukuran_file = $dokumen_file['file_size'];

    The reference is here: https://codeigniter.com/userguide3/libraries /file_uploading.html#class-reference

    reply
    0
  • Cancelreply