I got
failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in php when got file from Google Drive through Google Drive API.
My code below:
public function actionGetAllImagesFromDrive($fid, $path)
{
$client = $this->getGoogleClient();
$service = new \Google_Service_Drive($client);
$optParams = array(
'q' => "'$fid' in parents and trashed=false",
'fields' => '*'
);
$results = $service->files->listFiles($optParams);
$folderMimeType = 'application/vnd.google-apps.folder';
if (count($results->getFiles()) != 0) {
if (!is_dir($path)) {
mkdir($path, 0775, true);
}
foreach ($results->getFiles() as $file) {
if($file->getMimeType() == $folderMimeType) {
$this->actionGetAllImagesFromDrive($file->getId(), $path .'/'.$file->getName());
} else {
$url = $file->getWebContentLink();
$file_name = $path .'/'. $file->getName();
print_r("Downloading: ".$file->getName()."\n");
file_put_contents( $file_name, file_get_contents($url));
}
}
} else {
print_r("Folder is empty.\n");
}
}
This code will get all image from folder and sub folder on Google Drive.
How to solve this issue?