Php_get Data acquisition

Source: Internet
Author: User
Tags php file upload

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_ $_FILESObject

html代码中The following settings are required when uploading a file:

  1. When html表单中 you need to setenctype="multipart/form-data"
  2. 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 whilesleep(5)
    • wamp/tmpa file appears under the directory .tmp
    • .tmpThe 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

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.