PHP curl模拟form表单上传文件

关键代码如下:

$ch = curl_init('https://www.baidu.com/uploadImage');
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['file' => new \CURLFile($fileRealPath)]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);

备忘