設定

您的 PHP 5 應用程式需要經過妥善設定的 Google Cloud Storage 值區。只要您執行下列步驟,每個應用程式就能輕鬆存取這類值區:

  1. 針對您的專案啟用計費功能 (如果尚未啟用)。
  2. 在專案的 Storage「Browser」 中按一下「Create bucket」(建立值區)。

請注意,使用 Cloud Storage 值區可能會產生費用。每個專案都可以有一個預設值區,這個值區包括 5GB 的免費儲存空間及免費的 I/O 作業配額

使用預設值區的實用秘訣

使用預設值區時,您其實不需要知道值區名稱。您可以使用 #default#,這個值會在執行階段中替換為預設值區的名稱。

舉例來說,您可以使用 Cloud Storage 適用的 App Engine 串流包裝函式寫入預設值區:

$default_bucket = CloudStorageTools::getDefaultGoogleStorageBucketName();
file_put_contents("gs://${default_bucket}/hello_default.txt", $newFileContent);

$default_bucket = CloudStorageTools::getDefaultGoogleStorageBucketName();
$fp = fopen("gs://${default_bucket}/hello_default_stream.txt", 'w');
fwrite($fp, $newFileContent);
fclose($fp);