简体   繁体   中英

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

I'm new to codeigniter. i try using phpmyadmin database and i have troubled to edit an record.

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

this part of arsip.php in directory controller that line number show error

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

Whenever you get an error like:

Message: Undefined property: stdClass::$file

it means PHP can tell is looking at a stdClass object, however, it can not find (in this case) the property "file".

To debug this:

after $files = (object) $_FILES; and before $f_data = (object) $files->file; write:

die(var_vump($files)); 

This will tell you what is actually populating the object.

Also, my guess would be the input type="file" name is not set to "file" which is why PHP can't find it in the object.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM