当前位置: 首页 > 后端技术 > PHP

PHP发送和接收文件流

时间:2023-03-30 00:31:20 PHP

array('method'=>'POST','header'=>'content-type:application/x-www-form-urlencoded','content'=>file_get_contents($文件)));$context=stream_context_create($opts);$response=file_get_contents($url,false,$context);$ret=json_decode($response,true);返回$ret['成功'];}else{返回错误;$ret=sendStreamFile('http://127.0.0.1:81/stream.php','send.jpg');变量转储($ret);/**php接收流文件*@paramString$file接收后保存的文件名*@return布尔值*/functionreceiveStreamFile($receiveFile){$streamData=isset($GLOBALS['HTTP_RAW_POST_DATA'])?$GLOBALS['HTTP_RAW_POST_DATA']:'';if(empty($streamData)){$streamData=file_get_contents('php://input');}if($streamData!=''){$ret=file_put_contents($receiveFile,$streamData,true);}else{$ret=false;}返回$ret;}$receiveFile='receive.jpg';$ret=receiveStreamFile($receiveFile);echojson_encode(array('成功'=>(bool)$ret));?>