PHP的cURL支持通过给CURL_POSTFIELDS传递关联数组(而不是字符串)来生成multipart/form-data的POST请求
if (class_exists('CURLFile')) { $realPath=new CURLFile(realpath($filePath)); }else{ $realPath='@'.realpath($filePath);//php < 5.6 } $data['media']=$realPath; curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
不建议下面这种写法判断php版本
if (version_compare(phpversion(), '5.4.0') >= 0)