CodeIgniter实现文件上传时,报错:
You did not select afile to upload.解决方法:
将
$this->upload->do_upload();
改为
$this->upload->do_upload('userfile')
其中html页面的部分定义:
<?php echoform_open_multipart('upload/do_upload');?>
<input type="file"name="userfile" size="20"/> <br/><br />
<input type="submit"value="upload" />
</form>
CodeIgniter2.1用户手册里也介绍了:
$this->upload->do_upload()
根据你的偏好配置参数执行操作。注意:默认情况下上传的文件来自于提交表单里名为userfile的文件域,并且该表单必须是"multipart"类型:
<formmethod="post" action="some_action" enctype="multipart/form-data"/>
如果你想在执行do_upload函数之前自定义自己的文件域名称,可通过以下方法实现:
$field_name= "some_field_name";
$this->upload->do_upload($field_name)