File upload can be implemented through the HTTP protocol. To use the file upload function, you must first go to php. in the ini configuration file, make some settings for the upload, then understand the pre-defined variable $ _ FILES, use the value of $ _ FILES to restrict and determine the file to be uploaded, and finally use move_uploaded_file () function implementation Upload!
Php file upload-configure the php. inn file and the predefined variable $ _ FILES
File upload can be implemented through the HTTP protocol. To use the file upload function, you must first go to php. in the ini configuration file, make some settings for the upload, then understand the pre-defined variable $ _ FILES, use the value of $ _ FILES to restrict and determine the file to be uploaded, and finally use move_uploaded_file () function implementation Upload!
In the previous article, we introduced advanced applications of file operations, read/write, directory processing, and File Processing. Related articles:
Php file processing-writing and operating files
PHP directory processing-open/close a directory
PHP directory processing-browsing directories and operating directories
Php file processing advanced applications-remote file access and lock files
Php file processing advanced application-file pointer
Php file processing-how to read a file (one row, entire file)
Php file processing-read a file (one character, string)
Php file processing-open/close a file
Let's take a look. today we will introduce php file upload, pre-defined variables, and php. ini configuration!
I. configure the php. ini file
To smoothly implement the upload function, the first thing to do is to enable file upload in php. ini and make reasonable settings for some of the parameters. Find the File Upioads item and you can see that there are three attributes, which indicate the following:
File_uploads: if the value is on, the server supports file upload. if the value is off, the server does not.
Upload_tem_dir: temporary directory for uploading files. Before the file is successfully uploaded, the file is first stored in the temporary directory on the server. if you want to specify a location, set it here. Otherwise, use the default directory of the system.
Upload_max_filesize: maximum size of files that can be uploaded by the server, in MB. The default value is 2 MB.
In addition to the File Upolads item, several attributes also affect the File upload function.
Max_execution_time: maximum time for executing a command in PHP, in seconds;
Memory_limit: no memory space allocated by a command in PHP, in MB;
Note:
1. if you use the integrated installation package to configure the PHP development environment, the configuration information described above is configured by default!
2. if you want to upload a large file, you need. ini parameters are modified, including the maximum value of the files that can be uploaded by the upload_max_filesize server, the maximum time that a max_execution_time command can run, and the memory space allocated by a memory_limit command!
II. predefine variable $ _ FLIES
The $ _ FLIES variable stores information about the file to be uploaded, which plays a major role in the upload function. This variable is a two-dimensional array. The following table describes the predefined variables $ _ FILES:
| Element name |
Description |
| $ _ FILE [filename] [name] |
The file name that stores the uploaded file. For example, exam.txt, mydream.jpg, etc. |
| $ _ FILE [filename] [size] |
The size of the stored file, in bytes. |
| $ _ FILE [filename] [tmp_name] |
When a file is uploaded, it is saved as a temporary file in the temporary directory. This variable is a temporary file name. |
| $ _ FILE [filename] [type] |
The type of the file to be uploaded. |
| $ _ FILE [filename] [error] |
Stores the upload results. If the value is 0, the file is uploaded successfully. |
The following example creates an upload file field and outputs the uploaded file information through the $ _ FILES variable. The sample code is as follows;
$ Value) {// use the foreach loop to output the name and value of the uploaded file information echo $ name, "=". $ value ."
";}}?>
Output result:
In the next article, we will introduce the file upload function and multifile Upload. For more information, see "php file upload-move_uploaded_file () function usage details".
The above is the php file upload-configure the PHP. ini file and the predefined variable $ _ FILES. For more information, see other related articles in the first php community!