PHP form Upload Instance parsing

Source: Internet
Author: User
Tags php form

This article mainly and everyone to share the php form upload instance parsing, mainly in text and code to share with you, hoping to help everyone.

Form upload: Data from the browser side to the server side. (Transmitted when the browser sends a request to the server.) )

There are two types of data in the form: 1. String type (byte-stream encoding, which has a certain encoding rule)

2. File type (binary encoding, i.e. only binary transmission, not code rules)

<form action= ' method= ' enctype= ' > <input type= ' name= ' value= '        ></form>

In the Form tab:

Property action defines the action of the submission form, which specifies that the server script processes the uploaded form. If the action attribute is omitted, the current script processing is indicated;

The Method property specifies the HTTP methods to be used when submitting a form, with the default of Get, which is optional post and get two. (When the form data is visible in the address bar using GET, post is not visible);

The Enctype property specifies how the form data should be encoded before it is sent to the server, the property value is Application/x-www-form-urlencode (this is the default option, which means that all strings are encoded), multipart/ Form-data (this value must be used when uploading files), Text/plain (spaces converted to +, but special characters are not encoded)

In the Input tab:

The type attribute can have text (text input), radio (radio button), checkbox (multiple selection), submit (Form submit), password (password: Use encrypted form), file (document upload).

The Name property is required, and after the form is submitted, the values of each control are stored in the $_get or $_post array, and name is the array subscript for the corresponding value.

The Value property represents the values of the space, and if there is an external input, the value of the external input is stored, which is equivalent to a default value. This property is not required.

Data reception

After receiving the data from the browser, the server uses different processing methods according to the data type:

1. String type data is stored in the $_get/$_post variable.

2. File data, stored in a temporary directory (in a script cycle class saved, obsolete will be automatically deleted)

<! DOCTYPE html>


The password is not shown here because it is the type= ' password ' attribute.

After the upload is successful, var_dump ($_post) under the script specified in the server background gets the following result:


Only the string data is filled in the result, and the index value is table sole name, and the file data does not exist (stored in temp file in the system, and the time is the script period).

In php.ini, you can configure a temporary directory to upload files (the default off state), and if you do not manually change it, use the server system default temporary file directory temp.

Data processing

The main is to store the uploaded files (temporary files are automatically deleted after the end of the script).

Use function: Move_uploaded_file (temporary storage address, destination address);

The $_files array stores information about the uploaded file.


The ' filename ' subscript is the Name property that is written in the form.

The name in the two-dimensional array indicates the original file name, the type means the files (not the suffix), the tmp_name represents the temporary storage address, error indicates whether the error is incorrect, and the size of the upload file.

Function: STRRCHR (string, character), gets the position of the last occurrence of the character, and outputs the character and all subsequent characters.

STRCHR (string, character); Gets the position where the character first appears .....

PathInfo (variable); Gets the address, type, and name of the variable ...

Uniqid (); Name the uploaded file (avoid duplication). Uniqid (' Li_ '), which represents a string of generated strings preceded by a li_ prefix.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.