这是表单动作或其他事情
<?php
echo form_open_multipart("/Register/registerformModel",
array("name"=>"subform2","id"=>"subform2"));
?>
这是 HTML 文件
<input name="userfile" id="userfile" type="file" class="input"/>
这是用于将图像文件插入数据库的功能
public function registerformModel()
{
$this->load->model("common_model");
$config['upload_path'] = $this->config->item('upload_url_path').'images/member/';
$config['allowed_types'] = 'gif|jpg|png';
$config['file_name'] = date('Ymd_his_').rand(10,99).rand(10,99).rand(10,99);
$config['overwrite'] = FALSE;
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['max_filename'] = '0';
$config['remove_spaces'] = FALSE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$data['upload_data']['file_name'] = '';
echo $this->upload->display_errors('<p style="color:#FF0000;">','</p>');
}
else
{
$data = array('upload_data' => $this->upload->data());
$config['image_library'] = 'gd2';
$config['source_image'] = $config['upload_path'].$data['upload_data']['file_name'];
$config['quality'] = '100%';
$config['width'] = 50;
$config['height'] = 50;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$this->load->library('image_library', $config);
$this->image_lib->resize();
}
$data['query'] = array(
'image' => $data['upload_data']['file_name']
);
$num = $this->common_model->insert('member',$data['query']);
$msg = ($num > 0) ? $this->lang->line('added') : $this->lang->line('not_added');
$this->session->set_flashdata('msg', $msg);
}
查询运行成功,但未插入图像。