从过去几天开始,我一直在搜索如何使用Curl在PHP> = 5.5上传文件。最后,我找到了新的CurlFile方法,但无法使用远程URL。这是我正在使用的代码:
$access_token = 'MY_API_ACCESS_TOKEN';
$fields = array(
"name" => $name,
"parent" => array(
"id" => $folder_id
)
);
$another = array(
'attributes' => json_encode($fields),
'file' => new CurlFile($remoteUrl)
);
$header = array (
"Authorization: Bearer $access_token",
"Content-Type: multipart/form-data"
);
$options = array(
CURLOPT_URL => $UPLOAD_URL,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $another,
CURLOPT_HTTPHEADER => $header,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
用本地文件路径替换$remoteUrl
时一切正常。
问:使用CurlFile可以进行远程上传吗?如果是,我做错了什么?