Php_get Data acquisition
In PHP
, if you want to get get
data submitted through the method, you can get it through the $_GET
object (although the parameters 地址栏
can be viewed in the)
HTML code: Here is a simple form code to submit the data to 01.php
, using get
the way
<form action= "01.php" method= "get" > for = "" > Name: <input type= "text" Name= "UserName" ></label> <br/> for = "" > Mailbox: <input type= "text" Name= "UserEmail" ></label> <br/> <input type= "Submit" Name= "" ></form>
PHP Code:
<? PHP Echo "; Echo ' UserName: '. $_get [' UserName ']; Echo ' <br/> '; Echo ' UserEmail: '. $_get [' UserEmail '?>
Php_post Data acquisition
In PHP
, if you want to get post
data submitted through a method, you can $_POST
get the object
-
HTML code: here is a simple form code that submits the data to 02.php
, using the post
method (Note: The method in the code
changed to post
)
<form action= "02.php" method= "POST" > <label for = "" > Name: <input type= "text" name= "UserName" ></label> <b r/> <label for = "" > Mailbox: <input type= "text" name= "UserEmail" ></l abel> <br/> <input type= "Submit" name= "" ></FORM>
-
PHP Code:
<? PHP Echo "; Echo ' UserName: '. $_post [' UserName ']; Echo ' <br/> '; Echo ' UserEmail: '. $_post [' UserEmail '?>
Post&get Error Handling
When we direct access POST
GET
to the & page because there is no data transmission, there will be $_GET
$_POST
no corresponding key and error.
- Treatment Mode 1:
- Use
array_key_exists(key, 数组)
functions to make judgments
- Parameter 1: Key to detect
字符串
- Parameter 2: Array of tests
if (array_key_exists$_get)) { // If there is data to read again } Else { // Conversely, some other logic can be executed }
PHP File Upload processing 01_
$_FILES
Object
html代码中
The following settings are required when uploading a file:
- When
html表单中
you need to setenctype="multipart/form-data"
- Only
post
way PHP receive files can be $_FILES
obtained by
HTML code:
<form action= "03.fileupdate.php" method= "post" enctype= "Multipart/form-data" > for = "" > Photos: <input type= "file" name = "Picture" multiple= "" ></label> <br/> <input type= "Submit "Name=" "> </form>
PHP Code 01 This part of the code to test the specific contents of the $_files file
<? PHP Sleep (5); // let the server rest for a while Print_r ($_files);? >
Phenomenon:
- After clicking Submit, the server did not react immediately, but rested for a while
sleep(5)
wamp/tmp
a file appears under the directory .tmp
.tmp
The file will be automatically deleted in a minute.
- The contents of the server return, the name of the file
[name] => computer.png
, and the location where the file was savedD:\wamp\tmp\php3D70.tmp
PHP file Upload processing 02_ file Save
Just demonstrated the $_FILES
role of the object, and PHP
accept the upload file, will be saved in a temporary directory, then we will show how to 临时目录
save the following file.
HTML code: This part of the code does not need to change
<form action= "03.fileupdate.php" method= "post" enctype= "Multipart/form-data" > for = "" > Photos: <input type= "file" name = "Picture" multiple= "" ></label> <br/> <input type= " Submit "Name=" > </form>
PHP code move_uploaded_file()
This function can handle the file W3cschool_move_uploaded_file function interpretation
Array Array ( = = computer. PNG = image/png = D:\wamp\tmp\php8913. TMP = 0 [Size] = 5212 ) )
Where we need to picture
get through (depending on the properties of the form label name
) 临时文件名
and上传文件名
<? PHP Sleep (5); // let the server rest for a while so that we can view the uploaded temporary files/ /The first parameter is the file to be moved //The second parameter is the new location of the specified file move_uploaded_file( $_files[' picture '] [' tmp_name '], './upload/'. $_files [' Picture '] [' Name '?>
Php_get Data acquisition