2013-04-05 93 views
0

我試圖建立在我的笨功能的文件上傳..codeigniter上傳文件時出錯?

但無論怎樣我嘗試做,我得到一個錯誤......

誰能幫助我如何解決我的問題?

我在控制器中的功能。

function insert_user_details(){ 

      $this->load->library('form_validation'); 
      $this->form_validation->set_rules('UserName', 'Username', 'callback_username_check'); 
      //$this->form_validation->set_rules('Password', 'Password', 'required'); 
      //$this->form_validation->set_rules('Email', 'Email', 'required|email'); 
      //$this->form_validation->set_rules('FirstName','FirstName', 'required'); 
      //$this->form_validation->set_rules('MiddleName','FirstName', 'required'); 
      //$this->form_validation->set_rules('LastName','FirstName', 'required'); 

      if ($this->form_validation->run() == FALSE) 
      { 
       echo 'Please Fill in the Forms Correctly' ; 
      } 
      else 
      { 
       $config['upload_path'] = '../user_uploads/'; 
       $config['allowed_types'] = 'gif|jpg|png'; 
       $config['max_size'] = '100'; 
       $config['max_width'] = '1024'; 
       $config['max_height'] = '768'; 
       $this->load->library('upload', $config); 
       $pass = $this->input->post('Password'); 
       $pass = md5($pass); 
       $data = array(
        'UserName'=>$this->input->post('UserName'), 
        'Password'=>$pass, 
        'FirstName'=>$this->input->post('FirstName'), 
        'MiddleNames'=>$this->input->post('MiddleName'), 
        'LastName'=>$this->input->post('LastName'), 
        'DateOfBirth'=>date('Y-m-d',strtotime($_POST['DateOfBirth'])), 
        'AddressLine1'=>$this->input->post('AddressLine1'), 
        'AddressLine2'=>$this->input->post('AddressLine2'), 
        'City'=>$this->input->post('City'), 
        'CountryID'=>$this->input->post('CountryID'), 
        'NationalityCountryID'=>$this->input->post('NationalityCountryID'), 
        'MobileNo'=>$this->input->post('MobileNo'), 
        'WorkPhoneNo'=>$this->input->post('WorkPhoneNo'), 
        'WorkPhoneExtention'=>$this->input->post('WorkPhoneExtension'), 
        'NationalTaxNumber'=>$this->input->post('NationalTaxNumber'), 
        'NationalIDCardNo'=>$this->input->post('NationalIDCardNo'), 
        'MaritalStausID'=>$this->input->post('UI_LanguageID'), 
        'ReligionID'=>$this->input->post('ReligionID'), 
        'Photograph' => $this->upload->data(), 
        'Email'=>$this->input->post('Email'), 
        'WebUrl'=>$this->input->post('WebUrl'), 
        'HighestEducation'=>$this->input->post('HighestEducation'), 
        'UserResumeFile'=> 'res.jpg', 
        'UI_LanguageID'=> $this->input->post('UI_LanguageID'), 
        'LastLoginDate'=>'2013-02-24 00:00:00', 
        'LastLoginIP'=>'192.168.1.2', 
        'Remarks'=>$this->input->post('Remarks'), 
        'CreateByUserID'=>'1', 
        'CreateAt'=>'2013-02-24 00:00:00', 
        'ModifiedByUserID'=>'2', 
        'ModifiedAt'=>'2013-02-24 00:00:00', 
        'IsActive'=>'1' 
       ); 
       $table = 'sys_user_accounts'; 
       $this->common_model->insert_record($table, $data); 
       echo 'Success Message' ; 
       //$this->load->view('user_management/success','','true'); 
     } 
    } 

這裏是視圖文件。

'照片', 'ID'=> '照片', '佔位符'=> '上傳用戶照片', '的maxlength'=> '250' ); echo form_upload($ input_field_attributes); ?>

是的,我用的多

echo form_open_multipart('user_management/manage_users',array('id' => 'insert_user')); 

所以誰能告訴我爲什麼我的螢火得到這個錯誤之下?以及如何解決它?

> Error Number: 1054 

Unknown column 'Array' in 'field list' 

INSERT INTO `sys_user_accounts` (`UserName`, `Password`, `FirstName`, `MiddleNames`, `LastName`, `DateOfBirth`, `AddressLine1`, `AddressLine2`, `City`, `CountryID`, `NationalityCountryID`, `MobileNo`, `WorkPhoneNo`, `WorkPhoneExtention`, `NationalTaxNumber`, `NationalIDCardNo`, `MaritalStausID`, `ReligionID`, `Photograph`, `Email`, `WebUrl`, `HighestEducation`, `UserResumeFile`, `UI_LanguageID`, `LastLoginDate`, `LastLoginIP`, `Remarks`, `CreateByUserID`, `CreateAt`, `ModifiedByUserID`, `ModifiedAt`, `IsActive`) VALUES ('hello', '1a1dc91c907325c69271ddf0c944bc72', 'fda', 'fda', 'fad', '2010-03-03', '1', 0, '1', 0, 0, '1', '1', 0, '1', 0, 0, 0, Array, 0, 0, 0, 'res.jpg', 0, '2013-02-24 00:00:00', '192.168.1.2', 0, '1', '2013-02-24 00:00:00', '2', '2013-02-24 00:00:00', '1') 

Filename: C:\xampp\htdocs\projects\zorkif_nextgen\system\database\DB_driver.php 

Line Number: 330 

回答

0

在您的$ data數組上,'Photograph'索引指定$ this-> upload-> data()。其實$ this-> upload-> data()這個輔助函數返回一個數組。詳細here

如果您要保存照片的名字,試試這個

$name = $this->upload->data(); 

那麼你的陣列

'Photograph' => $name['file_name'] 
+0

我不明白你的觀點? 我應該怎麼寫呢, 你提供的鏈接,我已經看過那個文檔了。 你能告訴我哪一行應該更新哪些內容? – 2013-04-05 23:14:27

1

在我不是很熟悉的CI,但我可以看到$this->upload->data();正在返回一個數組,這就是它拋出一個錯誤的原因。

如果您使用的是PHP 5.4嘗試使用$this->upload->data()['file_name']$this->upload->data()['full_path'],如果你使用的是PHP 5.3或更低,不是簡單地分配$this->upload->data()一些變量,不是通過適當的鍵訪問值。

就在插入之前做這個var_dump($this->upload->data());,我相信你會發現它。

+0

得到您的觀點謝謝。但我沒有收到任何東西,空$ this-> upload-> data()['file_name'] 爲什麼它沒有得到任何值? – 2013-04-05 23:43:34

+0

嘗試var_dump($ this-> upload-> data());'並查看它包含的值。 – 2013-04-06 05:20:34

0

嘗試調試$this->upload->do_upload('image_file_name') //你的實際輸入申請的名稱

和上傳之前做檢查車況 //檢查是否上傳成功與否

if(!$this->upload->do_upload('image_file_name')) 
{ 
    // If all uploading condition not mate like image size/type etc. 
} 
+0

我不能看到圖像文件驗證。如果圖片上傳標準不會滿足您的處理方式。更好地驗證上傳的圖像文件對 $ config ['allowed_types'] ='gif | jpg | png'; $ config ['max_size'] ='100'; $ config ['max_width'] ='1024'; $ config ['max_height'] ='768'; – MaNKuR 2013-04-06 08:40:47

+0

檢查圖像上傳控制器功能[Here](http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html) – MaNKuR 2013-04-06 08:42:08

0

'Photograph' => $this->upload->data()

$此 - > upload-> data()是一個返回一個數組的CI函數,所以要將它插入到數據庫的列中,您需要序列化它,將其更改爲字符串或從arr中設置一個值ay爲照片領域。