This article mainly introduces the solution for "Youdidnotselectafiletoupload" when uploading images by Codeigniter. For more information, see the file upload class provided by Codeigniter, you can specify the file type to be uploaded and the file size to be specified. However, you need to pay attention to some minor issues during use. Otherwise, you will be caught off guard.
Many developers always encounter the "You did not select a file to upload" error when using the Codeigniter upload class. there is no error in the code. what is the problem?
1. the file domain name is modified.
Method 1:
For example, change the file domain name of the Views file to fileimg, and the default file domain name of CI is userfile, which is shown as follows:. This cannot be modified. Otherwise, the uploaded file cannot be found.
The principle is: $ this-> upload-> do_upload () by default, the form name of the file to be uploaded is userfile.
Method 2:
In fact, there is still a solution, if the file domain is another name. For example:
Set
The code is as follows:
$ This-> upload-> do_upload ();
Change
The code is as follows:
$ This-> upload-> do_upload ('imgfile ');
That's all!
2. form type
The form must use form_open_multipart. when HTML is formed, an attribute enctype = "multipart/form-data" is added. this is actually common sense. just pay attention to it.