php 发送与接收流文件
2023-09-27 14:27:00 时间
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); echo json_encode(array('success'=>(bool)$ret)); ?>
源代码下载地址:点击查看
相关文章
- PHP匿名函数和闭包
- php正则表达式基本
- php如何openssl_encrypt加密解密
- dedecms 后台修改系统设置,但是config.cache.inc.php文件不能写入
- PHP读取CSV文件
- PHP判断远程文件是否存在的几种方法
- 转:国内外著名开源b2c电子商务系统比较包括asp.net和php
- apache2 不支持php文件 解决办法
- php $_FILES处理文件上传
- PHP通过日志来发现问题
- Linux下将PHP添加到环境变量,将Mysql加入环境变量。
- PHP判断文件是否被引入的方法get_included_files
- php写文件操作
- PHP用户注册邮箱验证激活帐号
- php 二分查找法算法具体解释
- homebrew 安装nginx+php+mysql
- Nginx配置 隐藏入口文件index.php
- 【nginx】记录nginx+php-fpm实现大文件下载排坑的过程
- 从零开始创建一个 PHP 扩展
- PHP中的 Iterator 与 Generator
- php 文件加载方式
- 迅睿php图片大文件上传设置方法
- php中配置文件操作 如config.php文件的读取修改等操作
- 编写PHP代码总结
- php 两个文件之间的相对路径的计算方法
- PHP文件上传 (以上传txt文件为例)
- MySQL+PHP大文件读取和写库
- 自上而下,逐步揭开PHP解析大整数的面纱