php - codeigniter 在上传文件时出现错误?

标签 php mysql codeigniter

我正在尝试在 CodeIgniter 函数中设置文件上传..

但是无论我尝试做什么,我都会收到错误......

谁能帮我解决我的问题吗?

我在 Controller 中的功能。

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');
        }
    }

这是 View 文件。

'照片', 'id' => '照片', 'placeholder' => '上传用户照片', '最大长度' => '250' ); 回显 form_upload($input_field_attributes); ?>

是的,我使用了多部分

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

那么谁能告诉我为什么我在 firebug 中遇到以下错误?以及如何解决?

> 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

最佳答案

我不太熟悉 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()); 我相信您会明白的。

关于php - codeigniter 在上传文件时出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15844330/

相关文章:

php - 将 PHP 错误发送到默认错误日志和用户定义的错误日志

mysql - 获取mysql中的总列数

mysql - 显示经理下的所有用户(直接或间接)- SQL

mysql - 我如何从关系数据库迁移,我是否需要这样做?

php - 可以让 codeigniter 与另一个框架一起工作吗?

php - 仅在第一次尝试时无法建立 SSL 连接

php - 图像大小调整 Web 服务

php - PostgreSql 的 CodeIgniter2 + Sparks + Php-ActiveRecord 问题

mysql - Codeigniter MySql 数据库连接问题

php - 如何通过 SQL 在 PHP 中创建动态表