33 lines
1.0 KiB
PHP
33 lines
1.0 KiB
PHP
|
|
<?php
|
||
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/load_GoogleDrive.php';
|
||
|
|
|
||
|
|
// 이미지를 가져올 Google Drive 폴더 ID
|
||
|
|
$folderId = getFolderId($service, 'slider_images'); // 'slider_images'는 Google Drive의 폴더 이름
|
||
|
|
|
||
|
|
if ($folderId) {
|
||
|
|
// 폴더 내의 이미지 파일 목록 가져오기
|
||
|
|
$query = "'$folderId' in parents and mimeType contains 'image/' and trashed=false";
|
||
|
|
$response = $service->files->listFiles([
|
||
|
|
'q' => $query,
|
||
|
|
'spaces' => 'drive',
|
||
|
|
'fields' => 'files(id, name, webContentLink)'
|
||
|
|
]);
|
||
|
|
|
||
|
|
$images = [];
|
||
|
|
foreach ($response->files as $file) {
|
||
|
|
// 이미지 URL 생성
|
||
|
|
$imageUrl = "https://drive.google.com/uc?export=view&id=" . $file->id;
|
||
|
|
$images[] = [
|
||
|
|
'id' => $file->id,
|
||
|
|
'name' => $file->name,
|
||
|
|
'url' => $imageUrl
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
// JSON 형식으로 이미지 목록 반환
|
||
|
|
header('Content-Type: application/json');
|
||
|
|
echo json_encode($images);
|
||
|
|
} else {
|
||
|
|
echo json_encode(['error' => '폴더를 찾을 수 없습니다.']);
|
||
|
|
}
|
||
|
|
?>
|