发送端:

<?php

function curlPut($destUrl, $sourceFileDir, $headerArr = array(), $timeout = )
{
$ch = curl_init(); //初始化curl
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //返回字符串,而不直接输出
curl_setopt($ch, CURLOPT_URL, $destUrl); //设置put到的url
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证对等证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, ); //不检查服务器SSL证书 curl_setopt($ch, CURLOPT_PUT, true); //设置为PUT请求
curl_setopt($ch, CURLOPT_INFILE, fopen($sourceFileDir, 'rb')); //设置资源句柄
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($sourceFileDir)); $response = curl_exec($ch);
if ($error = curl_error($ch))
{
$bkArr = array(
'code' => ,
'msg' => $error,
);
}
else
{
$bkArr = array(
'code' => ,
'msg' => 'ok',
'resp' => $response,
);
} curl_close($ch); // 关闭 cURL 释放资源 return $bkArr;
} $destUrl = 'http://www.songjm.com/http_put_save.php';
$sourceFileDir = 'asset/pic.png';
$headerArr = array(
'filename:newname.png',
); $bkJson = curlPut($destUrl, $sourceFileDir, $headerArr);
$bkArr = json_decode($bkJson, true);
echo "<pre>";
print_r($bkArr);
die;

接收端:

<?php

if ($_SERVER['REQUEST_METHOD'] != 'PUT')
{
$bkMsg = array(
'code' => -,
'msg' => 'not put',
);
echo json_encode($bkMsg);
exit();
} $filename = $_SERVER['HTTP_FILENAME']; $fileSaveDir = 'upload/';
$newFile = $fileSaveDir.$filename; $handleToSave = fopen($newFile,'wb+');
$handleSource = fopen('php://input','rb'); while (!feof($handleSource))
{
fwrite($handleToSave, fread($handleSource, ));
} fclose($handleToSave);
fclose($handleSource); $bkMsg = array(
'code' => ,
'msg' => 'ok',
);
echo json_encode($bkMsg);
exit();

转自 https://www.cnblogs.com/songjianming/archive/2019/06/23/11072958.html

最新文章

  1. GestureDetectorl监听
  2. IOS - Create Push Segue Animation Without UINavigationController
  3. Android 带清除功能的输入框控件ClearEditText,仿IOS的输入框
  4. linux上使用amoeba实现MySql集群,以及读写分离,主从复制
  5. GPIO初始化之PB3/PB4/PA13/PA14/PA15引脚的复用--寄存器版本
  6. Eclipse : cannot open output file(c++)
  7. WCF序列化与反序列化问题
  8. SimpleDateFormat的线程安全问题
  9. 浅析 JavaScript 组件编写
  10. hdu1881(贪心+dp)
  11. drozer使用
  12. 【node】使用nvm管理node版本
  13. CSS属性速查表
  14. PHP开发——超全局数组变量
  15. Hadoop -- ES -- CURD
  16. Java零基础教程(二)基础语法
  17. django版本切换以及更改url(pycharm)
  18. New动态分配 Delete 释放内存
  19. android run/debug configurations时报错Cannot reload AVD list:
  20. CentOS7 更换OpenStack-queens源

热门文章

  1. vue-cli3.0 脚手架搭建项目的过程详解
  2. 【实战1】记一次提至administrator权限历程
  3. 国产MM才叫漂亮[景甜]
  4. 【Python学习】Python3 基础语法
  5. iframe使用总结(实战)
  6. car二手车购买原理
  7. Tensorflow细节-P62-完整的神经网络样例程序
  8. C++数组排序泛型算法
  9. CSP 初赛 知识点整理
  10. MySQL Create table as / Create table like