php發(fā)送與接收流文件的方法_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:php實(shí)現(xiàn)上傳圖片保存到數(shù)據(jù)庫的方法這篇文章主要介紹了php實(shí)現(xiàn)上傳圖片保存到數(shù)據(jù)庫的方法,可通過將圖片保存在數(shù)據(jù)庫實(shí)現(xiàn)多臺服務(wù)器共享文件的功能,非常具有實(shí)用價值,需要的朋友可以參考下 php實(shí)現(xiàn)上傳圖片保存到數(shù)據(jù)庫的方法。分享給大家供大家參考。具體分析如下: php 上傳圖片,一般都使用move_uploa
這篇文章主要介紹了php發(fā)送與接收流文件的方法,實(shí)例分析了php針對流文件的常見操作技巧,需要的朋友可以參考下
本文實(shí)例講述了php發(fā)送與接收流文件的方法。分享給大家供大家參考。具體如下:
sendStreamFile.php 把文件以流的形式發(fā)送
receiveStreamFile.php 接收流文件并保存到本地
sendStreamFile.php文件:
代碼如下: <?php/** php 發(fā)送流文件
* @param String $url 接收的路徑
* @param String $file 要發(fā)送的文件
* @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/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程序設(shè)計(jì)有所幫助。
分享:php+html5使用FormData對象提交表單及上傳圖片的方法這篇文章主要介紹了php+html5使用FormData對象提交表單及上傳圖片的方法,實(shí)例分析了FormData對象的使用技巧,非常具有實(shí)用價值,需要的朋友可以參考下 本文實(shí)例講述了php+html5使用FormData對象提交表單及上傳圖片的方法。分享給大家供大家參考。具體分析如下: FormData
相關(guān)PHP教程:
- php實(shí)現(xiàn)上傳圖片保存到數(shù)據(jù)庫的方法
- php+html5使用FormData對象提交表單及上傳圖片的方法
- php使用curl獲取https請求的方法
- Laravel 5.0 發(fā)布 新版本特性詳解
- Laravel模板引擎Blade中section的一些標(biāo)簽的區(qū)別介紹
- PHP框架Laravel的小技巧兩則
- Laravel中使用自己編寫類庫的3種方法
- PHP轉(zhuǎn)盤抽獎接口實(shí)例
- PHP中實(shí)現(xiàn)獲取IP和地理位置類分享
- PHP實(shí)現(xiàn)獲取FLV文件的時間
- PHP實(shí)現(xiàn)Javascript中的escape及unescape函數(shù)代碼分享
- Laravel中使用阿里云OSS Composer包分享
- 相關(guān)鏈接:
- 教程說明:
PHP教程-php發(fā)送與接收流文件的方法
。