从前端接收文件数据(formData形式),转化为二进制数据流请求接口返回
$photoFile = $_FILES['file'];
$data_buff=file_get_contents($photoFile['tmp_name']); //转化为二进制数据流
$auth = ""; //请求接口
$result = sendStreamFile($auth,$data_buff);
echo $result;
function sendStreamFile($url, $file) {
if (empty($url) || empty($file)) { return false; }
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'content-type:application/x-www-form-urlencoded',
'content' => $file
)
);
$context = stream_context_create($opts);
$response = file_get_contents($url, false, $context);
return $response;
}