How to solve the problem that PHP form $_FILES is empty

小云云
Release: 2023-03-21 15:30:02
Original
3819 people have browsed it

This article mainly shares with you how to solve the problem when the PHP form $_FILES is empty. There are many situations where $_FILES cannot receive the value during file upload. To summarize, the common mistakes are as follows, which are also easy for everyone to make during use. mistake.
1. Forgot to add the enctype="multipart/form-data" attribute in the form, this is the most common mistake;
2. Forgot to turn on the file upload function file_uploads=on## in php.ini

#1. Forgot to add enctype="multipart/form-data" in form

When learning HTML, everyone knows that form is the most common way to submit data to the server, and in many data submissions Files will be uploaded from time to time. Of course, uploading file streams requires some special processing.

<form action="" method="post" enctype="multipart/form-data">
......
</form>
Copy after login

Why should we add enctype="multipart/form-data"? Let’s take a look at the explanation of the enctype attribute in the form

ValueDescriptionapplication/x -www-form-urlencodedEncode all characters before sending (default)multipart/form-datatext/plainSpaces are converted to "+" plus signs, but special characters are not encoded.
Do not encode characters .

This value must be used when using a form that contains a file upload control.

So multipart/form-data must be added when uploading files

2. File_uploads=on

## must be turned on in php.ini #The function of this option is to configure whether uploading files is allowed. If set to off, file upload is not allowed, so the value of $_FILES cannot be received, so it must be turned on if file upload is to be done.

This parameter is in the PHP configuration file php.ini.

Related recommendations:

Details of the $_FILES function in PHP

How to use $_FILES in php

php file upload-configure php.ini file and predefined variables $_FILES

The above is the detailed content of How to solve the problem that PHP form $_FILES is empty. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template