用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3341|回复: 3
收起左侧

关于文件上传的问题,这样写对不对呢?

[复制链接]
发表于 2008-5-6 15:55:31 | 显示全部楼层 |阅读模式
view:
------------------------------------
<?=form_open_multipart('center/becometgmember/iBecometgmember');?>
<div>
<div>
  <label for="cardid_pic">idcard:</label>
  <input type="file" name="cardid_pic" id="cardid_pic" />
</div>
<div>
  <input type="submit" name="Submit" value="提交申请" />
</div>
</form>

controller:
---------------------------
$cardid_pic = $this->input->post('cardid_pic');
//将文件上传到服务器
$data_result['result_upload'] = $this->becometgmember_model->UploadFile($cardid_pic);


model:
-----------------------------------
        function UploadFile($cardid_pic){
                $config['upload_path'] = './images/';
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size'] = '200';
                $config['max_width']  = '1024';
                $config['max_height']  = '768';
                $config['encrypt_name'] = TRUE;
                $config['remove_spaces'] = TRUE;
                $this->load->library('upload',$config);

                print_r($this->upload->do_upload());

                if ($this->upload->do_upload()){
                        foreach ($this->upload->data() as $v){
                                $data['file_type'] = $v->file_type;
                                $data['raw_name'] = $v->raw_name;
                                $data['orig_name'] = $v->orig_name;
                                $data['file_size'] = $v->file_size;
                                $data['image_width'] = $v->image_width;
                                $data['image_height'] = $v->image_height;
                        }
                        return $data;
                }else{
                        return FALSE;
                }
        }

错误提示:
----------------------
You did not select a file to upload.

问题:
------------------------
怎么才能将选择的文件传递到model中?post好像不行。
头像被屏蔽
发表于 2008-5-11 20:15:14 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2008-5-12 21:42:13 | 显示全部楼层

你的文件域的name错了,应该是userfile

你的文件域的name错了,应该是userfile,如果你在Upload类里改过了,就不是这个问题;如果没改,那么就是你的文件域的name错了,
发表于 2008-5-23 11:54:43 | 显示全部楼层
$cardid_pic = $this->input->post('cardid_pic');
//将文件上传到服务器
$data_result['result_upload'] = $this->becometgmember_model->UploadFile($cardid_pic);

这些没必要。设置
$field_name = "cardid_pic";
  $this->upload->do_upload($field_name);

本版积分规则