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.