liu1084 发表于 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好像不行。

ackiae86 发表于 2008-5-11 20:15:14

judy_zyzyx 发表于 2008-5-12 21:42:13

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

你的文件域的name错了,应该是userfile,如果你在Upload类里改过了,就不是这个问题;如果没改,那么就是你的文件域的name错了,

gz123 发表于 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);
页: [1]
查看完整版本: 关于文件上传的问题,这样写对不对呢?