更新时间:2023-02-24 12:38:19
找到答案了,我需要 json_encode
属性数组,然后使用 new \CURLFile()
函数创建文件句柄,它不适用于 realpath()
Found the answer, i needed to json_encode
the attributes array and then use new \CURLFile()
function to create a file handle, it did NOT work with realpath()
$attributes = array('name'=>$fileName,'parent'=>array('id'=>$folderId));
$file = new \CURLFile($filePath);
$fields = array('attributes' => json_encode($attributes), 'file' => $file);
$headers = array("Authorization: Bearer ".$accessToken);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uploadUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($ch);