由于rest api使用多表单,所以我尝试使用curl发布一个文件。
这是我目前所拥有的。
$curlFile = new \CURLFile("shirt.png");
$data = array
(
"apikey" => $key,
"isTgaUploadEnabled" => "True",
"onVerificationPage" => "False",
"file" => $curlFile,
);
curl_setopt_array($curl, array(
CURLOPT_HEADER => TRUE,
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POSTFIELDS => $data,
));
使用CURLFile类不能工作,有什么建议吗?
发布于 2018-09-04 04:46:03
您在PHP5.5及更高版本上正在寻找以下内容:
$file = new CURLFile('cats.jpg','image/jpeg','test_name');
$args= array('test_file' => $file);
或在PHP5.4或更低版本上:
$args['file'] = '@/path/to/file';
但不要忘了设置适当的标志:
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args);
https://wiki.php.net/rfc/curl-file-upload
https://stackoverflow.com/questions/52137542
复制相似问题