直接上代码
服务器A代码:file_cli.php
<?php
function uploadToFileServer()
{
$filePath = $_SERVER['DOCUMENT_ROOT'] . '/Uploads/123.docx';
$url = 'http://file.com/file_server.php';
$data = array(
'file' => new \CURLFile(realpath($filePath))
);
$result = json_decode(f_curl($url, false, 'POST', $data), true);
$newPath = $url . $result['path']; // 新文件访问地址
$bool = unlink($filePath); // 删除本地文件
print_r($result);
print_r($newPath);
print_r($bool);
}
/**
* curl 请求
* @author Lycan <LycanCoder@gmail.com>
* @date 2018/09/14
*
* @param $curl
* @param bool $https
* @param string $method
* @param null $data
* @return mixed
*/
function f_curl($curl, $https = true, $method = 'GET', $data = null)
{
$ch = curl_init();