How PHP responds to post requests to upload files

Source: Internet
Author: User
Tags eol php programming
This article describes a PHP response to a POST request Uploading FilesThe method. Share to everyone for your reference, as follows:

function Send_file ($url, $post = ', $file = ') {$eol = "\ r \ n";  $mime _boundary = MD5 (time ());  $data = ";  $confirmation = ";  Date_default_timezone_set ("Asia/shanghai");  $time = Date ("y-m-d h:i:s");  $post ["filename"] = $file [filename];    foreach ($post as $key = = $value) {$data. = '--'. $mime _boundary. $eol; $data. = ' Content-disposition:form-data;    '; $data. = "Name=". $key. $eol.    $eol; $data. = $value.  $eol; } $data. = '--'. $mime _boundary.  $eol; $data. = ' Content-disposition:form-data; Name= '. $file [name]. '; Filename= '. $file [filename].  $eol; $data. = ' Content-type:text/plain '.  $eol; $data. = ' Content-transfer-encoding:binary '. $eol.  $eol; $data. = $file [Filedata].  $eol; $data. = "--". $mime _boundary. "--" . $eol.  $eol;  $params = Array (' http ' = = Array (' method ' = ' + ' POST ', ' header ' = ' content-type:multipart/form-data;boundary= '). $mime _boundary.  $eol, ' content ' = $data)); $ctx = Stream_contexT_create ($params);  $response = file_get_contents ($url, File_text, $ctx); return $response;}

I hope this article is helpful to you in PHP programming.

The above describes the PHP response to post requests to upload files, including the content of uploading files, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.