Learning points:
1.PHP upload configuration
2.$_FILES array
3.PHP upload function
Although most people think of the Web as only consisting of web pages, the HTTP protocol can actually transfer any file, such as office
documents, PDFs, executables, AVIs, compressed files, and various other file types. While FTP has historically been the standard way to upload files to servers, uploading files via the web is also becoming increasingly popular.
1. PHP upload configuration
There are some configuration directives that can be used to fine-tune PHP's file upload functionality. These directives are used to determine whetherPHP's file upload is enabled, the maximum allowed upload file size, the maximum allowable script memory allocation, and various other important
resources.
1.file_uploads=on|off: Determine whether the PHP script on the server can accept file uploads.
2.max_execution_time=integer: The maximum time, in seconds, that a PHP script can execute before registering a fatal error
.
3.memory_limit=integer: Set the maximum memory that the script can allocate, in MB. This prevents
runaway scripts from monopolizing server memory.
4.upload_max_filesize=integer: Set the maximum size of uploaded files in MB. This directive must be
smaller than post_max_size.
5.upload_tmp_dir=string: Set the uploaded file to be stored in a temporary location on the server before processing,
until the file is moved to the final destination.
6.post_max_size=integer: Determine the maximum size of information that can be accepted through the POST method, in MB as
unit.
2. $_FILES array
HTML of upload form
<span <</span><span form </span><span enctype</span><span ="multipart/form-data"</span><span action</span><span ="upload.php"</span><span method</span><span ="post"</span><span ></span> <span <</span><span input </span><span type</span><span ="hidden"</span><span name</span><span ="MAX_FILE_SIZE"</span><span value</span><span ="1000000"</span> <span /></span><span 上传文件: </span><span <</span><span input </span><span type</span><span ="file"</span><span name</span><span ="userfile"</span> <span /></span> <span <</span><span input </span><span type</span><span ="submit"</span><span value</span><span ="上传"</span> <span /></span> <span </</span><span form</span><span ></span>ENCTYPE="multipart/form-data", this is the fixed writing method, otherwise the file upload will fail
ACTION="upload.php", define the path of the program file to be processed
METHOD="post", Define the transmission method as POST. Generally, Form submission data is set to POST
defines the upper limit of uploaded file size. When this value is exceeded, the upload fails. It must be defined in front of the file upload domain.
And the value defined here cannot exceed the value set by upload_max_filesize in the php.ini file, otherwise it will be meaningless. (Note: The value of MAX_FILE_SIZE is only for the browser A suggestion, in fact it can be bypassed by simply
so don't rely on browser restrictions. In fact, the maximum value for uploading files in PHP.ini settings is. It won't work. But it's better to add MAX_FILE_SIZE to the form, because it can avoid
the trouble of users spending time waiting to upload a large file only to find that the file is too big)
can be customized, this value will be used in the code file.
.
1. The value stored in the $_FILES["userfile"]["tmp_name"] variable is the location where the file is temporarily stored in the Web server.
2. The value stored in the $_FILES["userfile"]["n name"] variable is the file name in the user system.
3. The value stored in the $_FILES["userfile"]["size"] variable is the byte size of the file.
4. The value stored in the $_FILES["userfile"]["type"] variable is the MIME type of the file, for example: text/plain
or image/gif.
5. The value stored in the $_FILES["userfile"]["error"] variable will be any error code related to file upload.
This is a new feature added in PHP4.2.0. error provides some array constants respectively: 0: means no error occurred, 1:
means the size of the uploaded file exceeds the agreed value. The maximum file size is specified in the PHP configuration file, the directive
is upload_max_filesize. 2: Indicates that the uploaded file size exceeds the maximum value specified by the MAX_FILE_SIZE element of the HTML form. 3: Indicates that the file is only partially uploaded. 4: Indicates that no files are uploaded.
<?<span php </span><span print_r</span>(<span $_FILES</span><span ); </span>?>3. PHP upload function
PHP's file system library provides a large number of file processing functions. In addition, PHP also provides two functions dedicated to the file upload process: is_uploaded_file() and move_uploaded_file(). 1. Determine whether to upload the file: is_uploaded_file()
2. Move uploaded files: move_uploaded_file()
<?<span php </span><span if</span> (<span is_uploaded_file</span>(<span $_FILES</span>["userfile"]["tmp_name"<span ])) { </span><span echo</span> '已经上传到临时文件夹'<span ; } </span><span else</span><span { </span><span echo</span> '失败'<span ; } </span>?>Note: The article comes from Li Yanhui’s PHP video tutorial. This article is for communication only and may not be used for commercial purposes, otherwise you will be responsible for the consequences.
<?<span php </span><span if</span> (!<span move_uploaded_file</span>(<span $_FILES</span>["userfile"]["tmp_name"],<span $_FILES</span>["userfile"]["name"<span ])) { </span><span echo</span> '移动失败'<span ; </span><span exit</span><span ; } </span>?>

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool