Home >Backend Development >PHP Problem >What is the use of php post method?
php post method allows users to upload text and binary files, and using PHP's authentication and file operation functions, you can fully control who is allowed to upload and how to process the file after uploading. Use syntax such as "method="POST "".
POST method upload
This feature allows users to upload text and binary files. Using PHP's authentication and file manipulation functions, you have full control over who is allowed to upload and what to do with files after they are uploaded.
Recommended: "PHP Tutorial"
PHP can accept any browser that complies with the RFC-1867 standard (including Netscape Navigator 3 and higher, patched Microsoft Internet Explorer 3 or higher).
Note: For related settings
Please refer to the file_uploads, upload_max_filesize, upload_tmp_dirpost_max_size and max_input_time setting options of php.ini.
Please note that PHP also supports the PUT method of file upload, which is used by Netscape Composer and the W3C's Amaya client.
Example #1 File upload form
You can create a special form to support file upload as follows:
<!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="__URL__" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form>
The __URL__ in the above example should be replaced and point to a Real PHP files.
MAX_FILE_SIZE The hidden field (unit is bytes) must be placed before the file input field, and its value is the maximum size of the received file. This is a recommendation for browsers, PHP will also check this. This setting can be easily bypassed on the browser side, so don't expect to use this feature to block large files. In fact, the maximum upload file size in PHP settings will not expire. But it is better to add this item to the form, because it can avoid the trouble of users spending time waiting for large files to be uploaded only to find that the file is too large and the upload failed.
Note:
Make sure the attribute of the file upload form is enctype="multipart/form-data", otherwise the file cannot be uploaded.
Global variable $_FILES exists since PHP 4.1.0 (replaced by $HTTP_POST_FILES in earlier versions). This array contains information about all uploaded files.
The contents of the $_FILES array in the above example are as follows. Let's assume that the name of the file upload field is userfile as shown in the example above. The name can be whatever you want.
$_FILES['userfile']['name']
The original name of the client machine file.
$_FILES['userfile']['type']
The MIME type of the file, if the browser provides this information. An example is "image/gif". However, this MIME type is not checked on the PHP side, so don't take it for granted.
$_FILES['userfile']['size']
The size of the uploaded file, in bytes.
$_FILES['userfile']['tmp_name']
The temporary file name stored on the server after the file is uploaded.
$_FILES['userfile']['error']
Error code related to the file upload. This project was added in PHP version 4.2.0.
After the file is uploaded, it will be stored in the default temporary directory of the server by default, unless upload_tmp_dir in php.ini is set to another path. The default temporary directory on the server side can be reset by changing the environment variable TMPDIR of the PHP running environment, but setting it by running the putenv() function inside the PHP script has no effect. This environment variable can also be used to confirm that other operations are also performed on the uploaded file.
The above is the detailed content of What is the use of php post method?. For more information, please follow other related articles on the PHP Chinese website!