Files
sam-kd/load_GoogleDrive.php
hskwon aca1767eb9 초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경
- DB 연결 하드코딩 → .env 기반으로 변경
- MySQL strict mode DATE 오류 수정
2025-12-10 20:14:31 +09:00

46 lines
1.5 KiB
PHP

<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/session.php'; // 세션 파일 포함
require_once $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();
// 서비스 계정 JSON 파일 경로
$serviceAccountKeyFile = $_SERVER['DOCUMENT_ROOT'] . '/tokens/mytoken.json';
// Google Drive 클라이언트 설정
$client = new Google_Client();
$client->setAuthConfig($serviceAccountKeyFile);
$client->addScope(Google_Service_Drive::DRIVE);
// Google Drive 서비스 초기화
$service = new Google_Service_Drive($client);
// 특정 폴더 확인 함수
function getFolderId($service, $folderName, $parentFolderId = null) {
$query = "name='$folderName' and mimeType='application/vnd.google-apps.folder' and trashed=false";
if ($parentFolderId) {
$query .= " and '$parentFolderId' in parents";
}
$response = $service->files->listFiles([
'q' => $query,
'spaces' => 'drive',
'fields' => 'files(id, name)'
]);
return count($response->files) > 0 ? $response->files[0]->id : null;
}
// Google Drive에서 파일 썸네일 검사 및 반환
function getThumbnail($fileId, $service) {
try {
$file = $service->files->get($fileId, ['fields' => 'thumbnailLink']);
return $file->thumbnailLink ?? null; // 썸네일 URL이 있으면 반환, 없으면 null
} catch (Exception $e) {
error_log("썸네일 가져오기 실패: " . $e->getMessage());
return null; // 실패 시 null 반환
}
}
?>