I’m trying to upload a file to google drive using http header and CURL post, and I get a “not found” returned from google error.
I think it’s because of the way Im uploading the file via CURL, Because I never Did it.
Here’s My Code :
$file = file_get_contents("./ima.jpg");
$length = strlen($file);
test($file,$length);
function test($file,$length){
$url2="https://www.googleapis.com/upload/drive/v2/filesuploadType=media";
$header = array(
"Content-Type: image/jpeg",
"Content-Length:$length ",
"Authorization: Bearer $token",
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url2);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false);
curl_setopt ($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$file);
$data2 = curl_exec($ch);
echo $data2;
curl_close($ch);
}
The Token is set in a variable token, and it is a valid token because it works with listing files from google drive, Thank you !
uploadTypeis a parameter to the URL and needs to be separated using?, which means that in your case the URL should most likely be;See here for more detailed documentation.