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);
欢迎转载,转载时请注明来源。