如何将Google App Engine中的我的Codeigniter项目与Google云端存储相关联?
有什么想法吗?
答案 0 :(得分:0)
您可以使用PHP客户端库[1]。这里有一个将文件上传到存储桶的示例:
use Google\Cloud\Storage\StorageClient;
/**
* Upload a file.
*
* @param string $bucketName the name of your Google Cloud bucket.
* @param string $objectName the name of the object.
* @param string $source the path to the file to upload.
*
* @return Psr\Http\Message\StreamInterface
*/
function upload_object($bucketName, $objectName, $source)
{
$storage = new StorageClient();
$file = fopen($source, 'r');
$bucket = $storage->bucket($bucketName);
$object = $bucket->upload($file, [
'name' => $objectName
]);
printf('Uploaded %s to gs://%s/%s' . PHP_EOL, basename($source), $bucketName, $objectName);
}
[1] https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-php