duanjiwei1283 2014-09-25 03:21
浏览 86
已采纳

遇到PHP错误严重性:通知消息:未定义属性:stdClass :: $ file文件名:controllers / arsip.php行号: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);
}
  • 写回答

1条回答 默认 最新

  • doumuyu0837 2014-09-25 14:15
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵