PHP-02. File Upload, PHP save/Transfer uploaded files, common network transfer protocols, request messages and attributes, response messages and attributes

Source: Internet
Author: User
Tags ftp file file transfer protocol ftp file transfer ftp file transfer protocol

Relational arrays

Array ("Key" = "value",...);

Get No data size limit

No limit on post upload size

Do not specify the upload method, default is Get

File Upload

You need to add enctype = "Multipart/form-data" in the form attribute in HTML

<!--upload file must be set enctype ='Multipart/form-data'-<form action="text01.php"Method="Post"Enctype="Multipart/form-data"> <input type="file"Name="Upfile"> <input type="file"Name="Upfiletwo"> <input type="Submit"> </form>
    • Server-side code
    • $_files["File" ["Name"]-the name of the file being uploaded
    • $_files["File" ["type"]-the type of file being uploaded
    • $_files["File" ["Size"]-the size of the uploaded file, measured in bytes
    • $_files["File" ["Tmp_name"]-the name of the temporary copy of the file stored on the server
    • $_files["File" ["Error"]-error code caused by file upload

    • Move_uploaded_file (moving files)
      • Uploaded temporary files, will be automatically deleted in a while, we need to move them to the saved location
      • Move_uploaded_file Parameters:
        • Parameter 1: Moving the file
        • Parameter 2: Destination path
          move_uploaded_file($_FILES[‘photo‘][‘tmp_name‘], ‘./images/‘.test.jpg);
<?PHP//delay PHP for a while//Let the PHP code delay a second pass in seconds//sleep (3); //Output ResultsPrint_r ($_files); //the value of the $_files    /*Array ([upfile] = = Array ([name] = yangyang.jpg [Type] = Image/jpeg [Tmp_name] = D:\wamp\tmp\php cc56.tmp [ERROR] = 0 [size] = 18145))*/    //gets the uploaded file information relational array$FILEARR = $_files['Upfile']; //get the original name of the uploaded file$fileName = $FILEARR ['name']; Echo $fileName.'<br>'; //get the location saved on the server$filePath = $FILEARR ['Tmp_name']; Echo $filePath.'<br>'; //know how to save files in PHP//parameter 2 is written relative to the path relative to the Files folder of the PHP file saved as 123.pngMove_uploaded_file ($filePath,'mydownload/'. $fileName);?>
Common network transport Protocols

The agreement can be understood as a set of communication that is 规范 only possible when the double-counter used is in compliance with this set of specifications. For example, 嘿嘿 the understanding of the different, bring about the communication barrier. There are more rules on network protocols, what to do first, what to do

    • Common protocols
      • Http,https Hypertext Transfer Protocol
      • FTP File Transfer Protocol
      • SMTP mail Transport protocol
Monitoring Tools

Using the monitoring tool we can view these HTTP requests, as well as edit the request content, resend, etc.

    • Browser
      • Chrome,firefox Development Tools
    • Grab Bag Tool
      • Fiddler,charles
Request/Request Message

The request has been 客户端 issued, there are three main components: 请求行 ,, 请求头请求主体

    • Request Line:

      • Request Method:GET
      • RequestURL
      • HTTPProtocol version
    • Request Header

      • Here is the main set of information, including 客户端 ,服务器
User-agent: Browser specific types such as: user-agent:mozilla/5.0 (Windows NT 6.1; rv:17.0) gecko/20100101 firefox/17.0accept: What data types are supported by the browser such as: accept:text/html,application/xhtml+xml,application/xml;q=0.9; Accept-charset: What kind of encoding is used by the browser, such as: accept-charset:iso-8859-1accept-encoding: The browser supports decoding data compression format such as: Accept-encoding:gzip, Deflateaccept-language: The language environment of the browser, such as: Accept-language zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3host: The hostname of the request, allows multiple domain names to be in the same IP address, That is, the virtual host. Host:www.baidu.comConnection: Indicates whether a persistent connection is required. keep-alive/close,http1.1 default is persistent connection, which can take advantage of the persistent connection, when the page contains multiple elements (such as applets, pictures), significantly reducing the time it takes to download. To do this, the servlet needs to send a content-length header in the answer, and the simplest implementation is to write the content to Bytearrayoutputstream first and then calculate its size before formally writing the content. For example: connection:keep-alivecontent-length: Indicates the length of the request message body. Content-length must appear for the POST request. The Content-type:web server tells the browser the type and character set of the object it responds to. For example: content-type:text/html; The charset= ' gb2312 ' content-encoding:web server indicates what compression method (Gzip,deflate) is used to compress the objects in the response. For example: The Content-encoding:gzipcontent-language:web server tells the browser the language of the object it responds to. Cookies: The most common request headers, which each time the browser sends a cookie to the server, allows the server to store a small amount of data on the client. Referer: Contains a URL that the user represents from the pageGo to the page where the current request is being accessed. The server will know which page you are coming from. referer:http://www.baidu.com/

    • Request Body
      • Here is the data submitted to the server
      • It is important to note that if you are submitting data to the server, you need to set it in the request header Content-Type: application/x-www-form-urlencoded (manual setup is required in Ajax)
Response/Response Messages

The response message is 服务器 sent back 客户端 . Components are 状态行 , 响应头 ,响应主体

Common corresponding properties

Cache-Control 响应输出到客户端后,服务端通过该报文头属告诉客户端如何控制响应内容的缓存。 下面,的设置让客户端对响应内容缓存3600秒,也即在3600秒内,如果客户再次访问该资源,直接从客户端的缓存中返回内容给客户,不要再从服务端获取(当然,这个功能是靠客户端实现的,服务端只是通过这个属性提示客户端“应该这么做”,做不做,还是决定于客户端,如果是自己宣称支持HTTP的客户端,则就应该这样实现)。Cache-Control: max-age=3600ETag一个代表响应服务端资源(如页面)版本的报文头属性,如果某个服务端资源发生变化了,这个ETag就会相应发生变化。它是Cache-Control的有益补充,可以让客户端“更智能”地处理什么时候要从服务端取资源,什么时候可以直接从缓存中返回响应。ETag: "737060cd8c284d8af7ad3082f209582d"Location我们在Asp.net中让页面Redirect到一个某个A页面中,其实是让客户端再发一个请求到A页面,这个需要Redirect到的A页面的URL,其实就是通过响应报文头的Location属性告知客户端的,如下的报文头属性,将使客户端redirect到iteye的首页中:Location: http://www.google.com.hkSet-Cookie服务端可以设置客户端的Cookie,其原理就是通过这个响应报文头属性实现的。Set-Cookie: UserID=JohnDoe; Max-Age=3600; Version=1HTTP响应体:如果请求的是HTML页面,那么返回的就是HTML代码。如果是JS就是JS代码。HTTP响应头:而设置Cookie,缓存等信息就是在响应头属性设置的。HTTP响应行:主要是设置响应状态等信息。

Common response states

PHP-02. File Upload, PHP save/Transfer uploaded files, common network transfer protocols, request messages and attributes, response messages and attributes

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.