遇到PHP错误严重性:通知消息:未定义属性:stdClass :: $ file文件名:controllers / arsip.php行号:137

时间:2014-09-25 03:21:03

标签: php codeigniter

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

1 个答案:

答案 0 :(得分:0)

每当您收到如下错误:

Message: Undefined property: stdClass::$file

这意味着PHP可以告诉他们正在查看stdClass对象,但是,它无法找到(在这种情况下)属性&#34; file&#34;。

调试:

$files = (object) $_FILES;之后和$f_data = (object) $files->file;之前写道:

die(var_vump($files)); 

这将告诉您实际填充对象的内容。

另外,我的猜测是输入类型=&#34;文件&#34; name未设置为&#34; file&#34;这就是为什么PHP无法在对象中找到它。

希望这有帮助!