https://github.com/null-none/googledrivephp
Use API Google drive for upload files
https://github.com/null-none/googledrivephp
Last synced: 9 months ago
JSON representation
Use API Google drive for upload files
- Host: GitHub
- URL: https://github.com/null-none/googledrivephp
- Owner: null-none
- License: mit
- Created: 2015-09-02T06:18:14.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-09-02T07:15:03.000Z (over 10 years ago)
- Last Synced: 2025-01-26T09:28:38.437Z (11 months ago)
- Language: PHP
- Size: 734 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GoogleDrivePHP
Use API Google drive for upload files
```
composer install
```
Example code
```
setClientId('');
$client->setClientSecret('');
$client->setRedirectUri('');
$client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
$session_start();
if (isset($_GET['code']) || (isset($_SESSION['access_token']) && $_SESSION['access_token'])) {
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
} else
$client->setAccessToken($_SESSION['access_token']);
$service = new Google_Service_Drive($client);
$file = new Google_Service_Drive_DriveFile();
$file->setTitle('image.jpg');
$file->setDescription('image');
$file->setMimeType('image/jpeg');
$data = file_get_contents('image.jpg');
$createdFile = $service->files->insert($file, array(
'data' => $data,
'mimeType' => 'image/jpeg',
'uploadType' => 'multipart'
));
print_r($createdFile);
} else {
$authUrl = $client->createAuthUrl();
header('Location: ' . $authUrl);
exit();
}
?>
```