Bu konuda PHP ile subdomain.storage.googleapis.com/index.html alma kodunu paylaşacağım. Composer ile kütüphanenin yüklenmesi gerekiyor.
|
1
|
composer require google/cloud-storage |
key.json yazan kısma Google Cloud Services Api den indirdiğimiz json keyinin, index.html yazan kısmına da index.html dosyamızın yolunu giriyoruz.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<?phpputenv("GOOGLE_APPLICATION_CREDENTIALS=key.json");require 'vendor/autoload.php';use GoogleCloudStorageStorageClient;# Bucket oluşturma$projectId = 'proje idniz';# Instantiates a client$storage = new StorageClient([ 'projectId' => $projectId]);$bucketName = 'oluşturulacak bucket(site) adı';$bucket = $storage->createBucket($bucketName);# Dosya Yükleme$storage = new StorageClient();$bucket = $storage->bucket($bucketName);$object = $bucket->upload(fopen('index.html', 'r'),[ 'predefinedAcl' => 'publicRead']); |
İşlem sonrası bucketismi.storage.googleapis.com/index.html linki oluşmuş oluyor.
Blog linki https://www.batukay.com/php-google-storage-api-kullanimi


