The example in this article describes how PHP responds to post requests for upload files. Share to everyone for your reference, specific 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 your PHP programming.