本篇文章的内容是php的 发送与接收流文件 ,现在在这里分享给大家,也可以给有需要的朋友参考一下,大家一起过来看一看吧
php 发送与接收流文件
sendStreamFile.php 把文件以流的形式发送
receiveStreamFile.php 接收流文件并保存到本地
sendStreamFile.php
[php] view plain copy
<?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
FUDforum(FUD论坛)是一个基于PHP+MySQL/PostgreSQL构建的开源论坛系统,支持多种语言包括简繁中文;采用模板系统来控制界面外观;基于角色的 权限控制系统;提供短消息发送平台;提供审查和回收站系统;支持附件/投票/全文搜索/IP跟踪/用户禁用/电子报/自定义Tag/排列用户等级等。 该版本支持静态论坛页、全局的通知、嵌套的子论坛和爬虫检测等功能;新增对DB2、SQL
119
[php] view plain copy
<?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怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号