繁体   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