I have this curl request that is working but when I go to view the image after I download it, it wont open because it says “we don’t support this file format”?
Here’s the request, the data is coming from the Google Picker API. A user selects the file and on selection I ajax the data to this curl request to save it to our server:
//data coming from google picker api
public function pickerdwload() {
$data = $this->input->post();
$oAuthToken = $data['accesstoken'];
$fileId = $data['file_id'];
$getUrl = 'https://www.googleapis.com/drive/v3/files/' . $fileId;
$authHeader = 'Authorization: Bearer ' . $oAuthToken ;
$ch = curl_init($getUrl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [$authHeader]);
$data = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_errno($ch);
curl_close($ch);
file_put_contents("testdwld.jpg", $data);
}
Everything is working, and I’m picking regular jpg files so the file extension in file_put_contents should work but won’t let me open the downloaded image?
Also I’ve verified the data oauth token and file ID are good and correct.
I’ve tried different paths, adding things to the $getUrl string like ?alt=media. It’s a fairly simple curl request and it’s doing the job and adding it to my server. But I can’t open the file?
Dylan Oldham is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4