Codeigniter上传图片出现“You did not select a file to upload”错误解决办法
2014-06-12 17:34
961 查看
Codeigniter自带的文件上传类非常好用,您可以设置指定上传某类型的文件及指定大小的文件。不过在使用的过程中需要注意一些小问题,否则会让你感到措手不及。
很多开发人员在使用Codeigniter的upload上传类时候,总是出现“You did not select a file to upload”错误,从代码里面看并没有什么错误,这是怎么回事呢?
1、文件域的名字被修改
方法一:
例如将Views文件的文件域的名字修改成了fileimg,而CI默认的文件域的名字是userfile,即形如:<input type="file" name="userfile" size="20" />。这个是不能修改的,否则就会找不到上传文件。
原理就是:$this->upload->do_upload()默认上传文件的表单名为userfile。
方法二:
其实还有解决方法,如果文件域是其他名字。比如:
<input type="file" name="imgfile" size="20" />
将
复制代码 代码如下: $this->upload->do_upload();改为
复制代码 代码如下: $this->upload->do_upload(‘imgfile');这样就可以了!
2、form表单类型
form表单需要使用form_open_multipart,形成HTML的时候会增加了一个属性enctype="multipart/form-data",这个其实是常识了,注意一下就好。
您可能感兴趣的文章:
相关文章推荐
- Codeigniter上传图片出现“You did not select a file to upload”错误解决办法
- PhpMyaAmin导入sql文件时出现You probably tried to upload too large file的解决办法
- 编译时出现fatal error C1853: "debug/xxx.pch" is not a precomplied header file with......错误的原因及解决办法(转)
- 安卓真机调试出现Installation failed due to invalid APK file!错误的解决办法
- Apache刚装好重启出现You don't have permission to access / on this server. 错误的解决办法
- Codeigniter出现Unable to connect to your database server using the provided settings错误解决办法
- 在Ubuntu安装完成后更改默认的语言LANG,出现Cannot set LC_CTYPE to default locale: No such file or directory错误的解决办法
- 在Ubuntu安装完成后更改默认的语言LANG,出现Cannot set LC_CTYPE to default locale: No such file or directory错误的解决办法
- Android项目导入时,出现的Could not write file 。。。.classpath错误的解决办法
- 打开sln文件出现 “the selected file is not a valid visual studio solution file”错误提示解决办法
- git push 出现 you are not allowed to upload merges 错误提示
- 打开sln文件出现the selected file is not a valid visual studio solution file错误提示解决办法
- 在Ubuntu安装完成后更改默认的语言LANG,出现Cannot set LC_CTYPE to default locale: No such file or directory错误的解决办法
- CodeIgniter “The filetype you are attempting to upload is not allowed.”解决
- Android项目导入时,出现的Could not write file 。。。。。。.classpath错误解决办法
- SQLServer2005打开表时出现“Object reference not set to an instance of an object. (SQLEditors)”错误的解决办法
- 打开VMware出现Reason: Failed to lock the file.错误的解决办法
- Android项目导入时,出现的Could not write file 。。。。。。.classpath错误解决办法
- Godaddy服务器发送邮件出现Could not connect to SMTP host错误 解决办法
- Codeigniter出现Unable to load the requested class: zebra_pagination错误解决办法