將檔案大小插入資料庫
P粉986860950
P粉986860950 2023-09-13 12:14:32
0
1
727

我正在上傳文件,並且大小在資料庫中保持為 0

$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');
        }

這段程式碼運作良好,但在 ukuran_file 欄位上保持插入 0。如何將檔案大小插入資料庫? ...

P粉986860950
P粉986860950

全部回覆(1)
P粉248602298

而不是

$ukuran_file = $dokumen_file['size'];

你必須使用

$ukuran_file = $dokumen_file['file_size'];

參考在這裡:https://codeigniter.com/userguide3/libraries /file_uploading.html#class-reference

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板