在php中发布文件
由于RESTAPI使用了多种形式,所以我尝试使用curl发布一个文件 这是我目前拥有的在php中发布文件,php,curl,Php,Curl,由于RESTAPI使用了多种形式,所以我尝试使用curl发布一个文件 这是我目前拥有的 $curlFile = new \CURLFile("shirt.png"); $data = array ( "apikey" => $key, "isTgaUploadEnabled" => "True", "onVerificationPage" => "False", "file" => $
$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类不起作用,对我应该做什么有什么建议吗?您正在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);