Initial commit

This commit is contained in:
Porawit Dongwang
2026-09-16 23:20:08 +07:00
commit 0041668dbb
32577 changed files with 3687927 additions and 0 deletions
+70
View File
@@ -0,0 +1,70 @@
<?php
// gdrive.php
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php';
function getGoogleDriveClient() {
if (!class_exists('\Google\Client')) {
return null;
}
$client = new \Google\Client();
$client->setApplicationName('P4Q System');
$client->setScopes([\Google\Service\Drive::DRIVE_FILE]);
if (file_exists(GDRIVE_CREDENTIALS_PATH)) {
try {
$client->setAuthConfig(GDRIVE_CREDENTIALS_PATH);
return $client;
} catch (Exception $e) {
return null;
}
}
return null;
}
function uploadFileToDrive($filePath, $fileName, $folderId) {
$client = getGoogleDriveClient();
if (!$client || empty($folderId)) {
// Mock upload if no credentials or folder ID
return "mock_file_id_" . uniqid();
}
$service = new \Google\Service\Drive($client);
$fileMetadata = new \Google\Service\Drive\DriveFile([
'name' => $fileName,
'parents' => [$folderId]
]);
$content = file_get_contents($filePath);
try {
$file = $service->files->create($fileMetadata, [
'data' => $content,
'mimeType' => mime_content_type($filePath),
'uploadType' => 'multipart',
'fields' => 'id'
]);
return $file->id;
} catch (Exception $e) {
return "mock_file_id_err_" . uniqid();
}
}
function deleteFileFromDrive($fileId) {
if (strpos($fileId, 'mock_file_id') === 0) {
return true;
}
$client = getGoogleDriveClient();
if (!$client) {
return true;
}
$service = new \Google\Service\Drive($client);
try {
$service->files->delete($fileId);
return true;
} catch (Exception $e) {
return false;
}
}