本文实例讲述了PHP响应post请求上传文件的方法。分享给大家供大家参考,具体如下:
$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;
}
希望本文所述对大家PHP程序设计有所帮助。
原文链接:https://www.f2er.com/php/20769.html