PHP 使用Curl将用户上传的文件发送给其他服务器

$url = 'http://xxxx.xx/xxxx';

$file = $_FILES['file'];
$filename = $file['name'];
$filepath = $file['tmp_name'];
$filetype = $file['type'];

$data = ['file' => new \CURLFile(realpath($filepath), $filetype, $filename)];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return_data = curl_exec($ch);
curl_close($ch);

 

posted @ 2023-08-30 14:27  何效名  阅读(216)  评论(0编辑  收藏  举报