Codeigniter上传图片出现“You did not select a file to upload”错误解决办法
这篇文章主要介绍了Codeigniter上传图片出现“You did not select a file to upload”的解决办法,需要的朋友可以参考下
Codeigniter自带的文件上传类非常好用,您可以设置指定上传某类型的文件及指定大小的文件。不过在使用的过程中需要注意一些小问题,否则会让你感到措手不及。
很多开发人员在使用Codeigniter的upload上传类时候,,总是出现“You did not select a file to upload”错误,从代码里面看并没有什么错误,这是怎么回事呢?
1、文件域的名字被修改
方法一:
例如将Views文件的文件域的名字修改成了fileimg,而CI默认的文件域的名字是userfile,即形如:。这个是不能修改的,否则就会找不到上传文件。
原理就是:$this->upload->do_upload()默认上传文件的表单名为userfile。
方法二:
其实还有解决方法,如果文件域是其他名字。比如:
将
复制代码 代码如下:
$this->upload->do_upload();
改为
复制代码 代码如下:
$this->upload->do_upload(‘imgfile');
这样就可以了!
2、form表单类型
form表单需要使用form_open_multipart,形成HTML的时候会增加了一个属性enctype="multipart/form-data",这个其实是常识了,注意一下就好。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.