2014-09-25 59 views
1

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

爲什麼要把它作爲一個對象?爲什麼不使用'$ _FILES'的聯合索引? – Ghost 2014-09-25 03:22:53

+0

文件html元素的名稱是什麼? – 2014-09-25 05:23:52

回答

0

當你得到這樣的錯誤:

Message: Undefined property: stdClass::$file 

這意味着PHP可以告訴正在看一個stdClass對象,但是,它找不到(在這種情況下)屬性「文件」。

要調試此:

$files = (object) $_FILES;之前$f_data = (object) $files->file;寫:

die(var_vump($files)); 

這會告訴你什麼是真正的填充物。

此外,我的猜測是輸入類型=「文件」名稱未設置爲「文件」,這就是爲什麼PHP無法在對象中找到它。

希望這會有所幫助!

相關問題