PHP method for responding to the post request to upload files

Source: Internet
Author: User
Tags eol
This article mainly introduces the PHP method for responding to the post request to upload files, and involves php techniques for post transmission data processing, for more information about how PHP responds to post requests, see the following example. We will share this with you for your reference. The details are 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 will help you with PHP programming.

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.