


The system array used by PHP to receive uploaded file information is $_FILES.
In PHP, we often need to handle file uploads, such as uploading pictures, videos and other files. In order to handle relevant information and data during the upload process, PHP provides a special system array $_FILES to store uploaded file information.
$_FILES variable is a two-dimensional associative array with the following structure:
$_FILES = array( 'file' => array( 'name' => 'filename.txt', //文件名 'type' => 'text/plain', //文件MIME类型 'tmp_name' => '/tmp/php/php1h4jCk', //上传的临时文件名 'error' => 0, //上传的错误代码 'size' => 123 //上传文件的大小 ) );
Among them, "file" in the array is the name of the form element, such as the following HTML code:
In this form, "file" is the name of the form element.
In $_FILES, the specific information stored includes:
- name: Uploaded file name.
- type: MIME type of uploaded file.
- tmp_name: The name of the uploaded temporary file, stored in the temporary directory on the server side.
- error: The error code of the uploaded file. If it is 0, it means the upload is successful.
- size: The size of the uploaded file.
The following is the meaning of each field in $_FILES:
- name
The original file name of the uploaded file, excluding the file path. If the file name is modified when a file is uploaded, this variable stores the new file name.
- #type
The MIME type of the uploaded file, that is, the content type of the file, such as text/plain, application/octet-stream, etc.
- tmp_name
The temporary file name of the uploaded file, and the path to store the temporary file. This path is the temporary directory on the server side.
- error
Error code for uploading files. If the upload is successful, this value is 0. Other possible values include:
- UPLOAD_ERR_OK:文件上传成功。 - UPLOAD_ERR_INI_SIZE:上传的文件超过了php.ini 中 upload_max_filesize 选项限制的值。 - UPLOAD_ERR_FORM_SIZE:上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。 - UPLOAD_ERR_PARTIAL:文件只有部分被上传。 - UPLOAD_ERR_NO_FILE:没有文件被上传。 - UPLOAD_ERR_CANT_WRITE:写入磁盘失败。 - UPLOAD_ERR_EXTENSION:PHP扩展停止文件上传。
- size
The size of the uploaded file, in bytes.
Example of using $_FILES variable:
If we want to upload an image in a form, we can use the following HTML code:
On the server side, we can use The following PHP code handles uploaded files:
<?php if(isset($_POST['submit'])) { $file = $_FILES['image']; $filename = $file['name']; $filetmp = $file['tmp_name']; $filesize = $file['size']; $filetype = $file['type']; // TODO: 处理上传文件 move_uploaded_file($filetmp, "uploads/" . $filename); } ?>
When processing uploaded files, we first check whether the submitted form contains the "submit" field. This is to avoid processing uploaded files without submitting the form. mistake.
We first get the file information from the $_FILES variable, and define the variables $filename, $filetmp, $filesize, and $filetype to store the file name, temporary file name of the uploaded file, file size, and MIME type respectively.
Next, we can use the PHP function move_uploaded_file() function to move the uploaded file from the temporary directory to the specified directory where we store the file, such as the "uploads/" directory in the above example.
Summary:
$_FILES is the key variable for processing file uploads in PHP. It contains various information about uploaded files, including file name, MIME type, upload temporary file name, size, etc. wait. When using $_FILES, we need to pay attention to the timing of form submission, the logic of processing uploaded files, and the storage method of uploaded files.
The above is the detailed content of Which system array does PHP use to receive uploaded file information?. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools