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' => '照片', 'placeholder' => '上传用户照片', '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
4

4 回答 4

1

我对 CI 不是很熟悉,但我可以看到它$this->upload->data();正在返回一个数组,这就是它抛出错误的原因。

如果您使用的是 PHP 5.4,请尝试使用$this->upload->data()['file_name']or $this->upload->data()['full_path'],如果您使用的是 PHP 5.3 或更低版本,则不要简单地分配$this->upload->data()给某个变量并通过适当的键访问值。

就在插入之前执行此操作var_dump($this->upload->data());,我相信您会弄清楚的。

于 2013-04-05T22:09:19.687 回答
0

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

$this->upload->data() 是一个返回数组的 CI 函数,因此要将其插入数据库中的列中,您需要对其进行序列化、将其更改为字符串或仅从数组中设置一个值对于照片字段。

于 2013-04-06T14:30:06.963 回答
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.
}
于 2013-04-06T08:35:08.680 回答
0

在您的 $data 数组中,您正在分配 $this->upload->data() 的“照片”索引。实际上 $this->upload->data() 这个辅助函数返回一个数组。详情在这里

如果你想保存照片的名字,试试这个

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

然后在你的数组中

'Photograph' => $name['file_name']
于 2013-04-05T22:09:05.780 回答