php – 使用CodeIgniter将上传图像字段添加到注册表单

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 使用CodeIgniter将上传图像字段添加到注册表单脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在 CodeIgniter添加一个上传图片字段来注册表单.

我在控制器中的注册码:

function add_new_ticket() {

    if ($this->input->post('fullname',TRUE)
        && $this->input->post('nID',TRUE)
        && $this->input->post('age',TRUE)
        && $this->input->post('gender',TRUE)
        // && $this->input->post('isFileiD',TRUE)
        // && $this->input->post('FileID',TRUE)
        && $this->input->post('phone',TRUE)
        && $this->input->post('tyPE',TRUE)
        && $this->input->post('opsType',TRUE)
        && $this->input->post('clienc',TRUE)
        && $this->input->post('dr',TRUE)
        && strlen($this->input->post('phone',TRUE)) >= 9
        && strlen($this->input->post('nID',TRUE)) >= 9
        && (int) $this->input->post('age',TRUE) <= 99
        && count(explode('-',$this->input->post('default-date',TRUE)) > 1)
    ){

我的模型文件中的代码

<?PHP
    class user extends CI_Model {

        public function add() {
            $data = array(
                'name' => $this->input->post('name'),'password' => $this->input->post('password'),'add_date' => time(),'email' => $this->input->post('email'),'birth_date' => $this->input->post('birth'),'phone' => $this->input->post('phone'),'mobile' => $this->input->post('mobile'),'sex' => $this->input->post('type'),'cITy' => $this->input->post('city'),'First_name' => $this->input->post('first_name'),'last_name' => $this->input->post('last_name'),'main_street' => $this->input->post('main_street'),'sub_street' => $this->input->post('sub_street'),'type' => $this->input->post('member_type'),'delegate_name' => $this->input->post('delegate_name'),'delegate_email' => $this->input->post('delegate_email'),'delegate_pass' => md5($this->input->post('delegate_pass')),'location' => serialize(array($this->input->post('lat'),$this->input->post('lng')))
            );
            $this->db->insert('admins',$data);
        }

        public function edit($id = FALSE) {

            $this->db->set('name',$this->input->post('name'));

            $this->db->set('email',$this->input->post('email'));
            $this->db->set('phone',$this->input->post('phone'));
            $this->db->set('mobile',$this->input->post('mobile'));
            $this->db->set('birth_date',$this->input->post('birth'));

            $this->db->set('first_name',$this->input->post('first_name'));
            $this->db->set('last_name',$this->input->post('last_name'));

            $this->db->set('city',$this->input->post('city'));

            $this->db->set('main_street',$this->input->post('main_street'));

            $this->db->set('sub_street',$this->input->post('sub_street'));

            if ($this->input->post('type')) {
                $this->db->set('sex',$this->input->post('type'));
            }

            if ($this->input->post('lat') and $this->input->post('lng')) {
                $this->db->set('location',serialize(array($this->input->post('lat'),$this->input->post('lng'))));
            }

            if ($this->input->post('password') !== '') {
                $this->db->set('password',md5($this->input->post('password')));
            }

            $this->db->where('id',$id);
            $this->db->update('admins');
        }

        public function del($id = FALSE) {
            $this->db->where('id',$id);
            $this->db->delete('admins');
        }
    }

我想添加一个允许上传图像的字段.

@L_304_13@

我假设您要在表单中添加“图像上传”选项

public function add() {



/* Configuration array VARIoUs settings

  can be set here

  **/
 $config['upload_path'] = '/file_path/'; // path where image will be saved
         $config['Allowed_types'] = 'gif|jpg|png|jpeg';
         $this->load->library('upload',$config);
         $this->upload->do_upload('image');
         $data_upload_files = $this->upload->data();

         $image = $data_upload_files[full_path];
$data = array(
        'name' => $this->input->post('name'),$this->input->post('lng')))
        'image'=>$image; // add this for image

    );
 $this->db->insert('admins',$data);

}

View有类似的东西

<input type="file" name="image" size="20" />

调节

function add_new_ticket() {

    if ($this->input->post('fullname',TRUE) 
        && $this->input->post('nID',TRUE) 
        && $this->input->post('age',TRUE) 
        // && $this->input->post('isFileID',TRUE) <= 99
        && $this->upload->do_upload() // add something like this              
&& count(explode('-',TRUE)) > 1)
            ){

注意:

输入名称必须在$this-> upload-> do_upload(‘image’)中定义为相同;即name =“image”

输入元素必须具有多个=“多个”或仅多个

3. $这 – >负载>库( ‘上传’); //加载库

4.回调,$this-> upload-> do_upload()会将在给定字段名称中选择的文件上传到目标文件夹.

5.回调$this-> upload-> data()返回与上传文件相关的数据数组,如文件名,路径,大小等.

脚本宝典总结

以上是脚本宝典为你收集整理的php – 使用CodeIgniter将上传图像字段添加到注册表单全部内容,希望文章能够帮你解决php – 使用CodeIgniter将上传图像字段添加到注册表单所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。