如何将PHP发送与接收流文件操作改写成长尾词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计202个文字,预计阅读时间需要1分钟。
1. [代码] sendStreamFile.phpPHP 发送流文件@param String $url 接收的路径@param String $file 要发送的文件@return booleanfunction sendStreamFile($url, $file){ if (file_exists($file)) { $opts=array( 'http'=> array( 'method'=> 'POST', 'header'=> Content-type: application/octet-stream\r\n, 'content'=> file_get_contents($file) ) ); $context=stream_context_create($opts); return @file_put_contents($url, fopen($file, 'r'), false, $context); } return false;}
1.[代码]sendStreamFile.php
<?php /** php 发送流文件 * @param String $url 接收的路径 * @param String $file 要发送的文件 * @return boolean */ function sendStreamFile($url, $file){ if(file_exists($file)){ $opts = array( 'localhost/fdipzone/receiveStreamFile.php', 'send.txt'); var_dump($ret); ?>
2.[代码]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)); ?>
本文共计202个文字,预计阅读时间需要1分钟。
1. [代码] sendStreamFile.phpPHP 发送流文件@param String $url 接收的路径@param String $file 要发送的文件@return booleanfunction sendStreamFile($url, $file){ if (file_exists($file)) { $opts=array( 'http'=> array( 'method'=> 'POST', 'header'=> Content-type: application/octet-stream\r\n, 'content'=> file_get_contents($file) ) ); $context=stream_context_create($opts); return @file_put_contents($url, fopen($file, 'r'), false, $context); } return false;}
1.[代码]sendStreamFile.php
<?php /** php 发送流文件 * @param String $url 接收的路径 * @param String $file 要发送的文件 * @return boolean */ function sendStreamFile($url, $file){ if(file_exists($file)){ $opts = array( 'localhost/fdipzone/receiveStreamFile.php', 'send.txt'); var_dump($ret); ?>
2.[代码]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)); ?>

