2013-04-05 92 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为照片领域。