簡體   English   中英

遇到PHP錯誤嚴重性:通知消息:未定義的屬性:stdClass :: $ file文件名:controllers / arsip.php行號:137

[英]A PHP Error was encountered Severity: Notice Message: Undefined property: stdClass::$file Filename: controllers/arsip.php Line Number: 137

我是Codeigniter的新手。 我嘗試使用phpmyadmin數據庫,但我無法編輯記錄。

A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$file
Filename: controllers/arsip.php
Line Number: 137

目錄控制器中這部分arsip.php的行號顯示錯誤

   function edit($id)
   {
    $judul = $this->input->post('no',TRUE);
    $config['file_name'] = $judul;
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'pdf|doc|docx';
    $config['max_size'] = '1000000';
    $data['title']="Edit data Arsip";
    $this->_set_rules();
    $this->load->library('upload', $config);
    $this->upload->initialize($config);
    $files = (object) $_FILES;
    $f_data = (object) $files->file; //is problem
    $file=$this->upload->file_name;
    $id = $this->input->post("no");

    if ($this->form_validation->run() == FALSE)
    {
        $result["msg"] = validation_errors();
        ;
        $result["success"] = false;
    }
    elseif($f_data->name != "")
    {   
        if (!$this->upload->do_upload("file")) {
            $result["content"]  = $this->upload->display_errors("", "");
            $result["success"]  = false;
        }
        else
        {
            $fdata = (object) $this->upload->data();

            $data = array(
            'no_arsip'=>$this->input->post('no'),
            'tahun'=>$this->input->post('tahun'),
            'nama_kapal'=>$this->input->post('nama_kapal'),
            'perihal'=>$this->input->post('perihal'),
            'file' => $fdata->file_name,
            );
            $this->m_arsip->update($id,$info);
            $data['arsip']=$this->m_arsip->cek($id)->row_array();
            $data['message']="<div class='alert alert-success'>Data berhasil diupdate</div>";
            redirect('arsip');
        }
    }
    else
    {
        $data = array(
            'no_arsip'=>$this->input->post('no'),
            'tahun'=>$this->input->post('tahun'),
            'nama_kapal'=>$this->input->post('nama_kapal'),
            'perihal'=>$this->input->post('perihal'),
        );
        $this->m_arsip->update($id,$info);
            $data['arsip']=$this->m_arsip->cek($id)->row_array();
            $data['message']="<div class='alert alert-success'>Data berhasil diupdate</div>";
            redirect('arsip');
    }   

    echo json_encode($result);
}

每當出現以下錯誤時:

Message: Undefined property: stdClass::$file

這意味着PHP可以確定正在查看stdClass對象,但是,在這種情況下,它找不到屬性“文件”。

要調試此:

$files = (object) $_FILES; 並且在$f_data = (object) $files->file; 寫:

die(var_vump($files)); 

這將告訴您實際填充對象的內容。

另外,我的猜測是輸入type =“ file”名稱沒有設置為“ file”,這就是為什么PHP在對象中找不到它的原因。

希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM