• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

如何通过php 发送与接收流文件

php 搞代码 4年前 (2022-01-22) 22次浏览 已收录 0个评论

php 发送与接收流文件

sendStreamFile.php 把文件以流的形式发送

receiveStreamFile.php 接收流文件并保存到本地

sendStreamFile.php

<?php/** php 发送流文件* @param  String  $url  接收的路径* @param  String  $file 要发送的文件* @return boolean*/function sendStreamFile($url, $file){    if(file_exists($file)){        $opts = array(            'http' => array(                'method' => 'POST',                'header' => 'content-type:application/x-www-form-urlencoded',                'content' => file_get_contents($file)            )        );        $context = stream_context_create($opts);        $response = file_get_contents($url, false, $context);        $ret = json_decode($response, true);        return $ret['success'];    }else{        return false;    }}$ret = sendStreamFile('http://localhost/fdipzone/receiveStreamFile.php', 'send.txt');var_dump($ret);?>

receiveStreamFile.php

<?php/** php 接收流文件* @param  String  $file 接收后保存的文件名* @return boolean*/function receiveStreamFile($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;    }    return $ret;}$receiveFile = 'receive.txt';$ret = receiveStreamFile($receiveFile<p>5本文来源gao!daima.com搞$代!码#网#</p><pre>搞代gaodaima码

);echo json_encode(array('success'=>(bool)$ret));?>

本文讲解了如何通过php 发送与接收流文件,更多相关内容请随时关注我们网站!

相关推荐:

如何通过php 对图片局部打马赛克

如何通过php 获取文件mime类型的方法讲解

如何通过php 获取Youtube某个User所有Video信息

以上就是如何通过php 发送与接收流文件的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何通过php 发送与接收流文件
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址