| 1 |
# Google Cloud Storage for PHP |
| 2 |
|
| 3 |
> Idiomatic PHP client for [](https://cloud.google.com/storage/Cloud Storage](https://cloud.google.com/storage/](https://cloud.google.com/storage/). |
| 4 |
|
| 5 |
[](https://packagist.org/packages/google/cloud-storage](https://packagist.org/packages/google/cloud-storage](https://packagist.org/packages/google/cloud-storage) [](https://packagist.org/packages/google/cloud-storage](https://packagist.org/packages/google/cloud-storage](https://packagist.org/packages/google/cloud-storage) |
| 6 |
|
| 7 |
* [](https://cloud.google.com/php/docs/reference/cloud-storage/latestAPI documentation](https://cloud.google.com/php/docs/reference/cloud-storage/latest](https://cloud.google.com/php/docs/reference/cloud-storage/latest) |
| 8 |
|
| 9 |
**NOTE:** This repository is part of [](https://github.com/googleapis/google-cloud-phpGoogle Cloud PHP](https://github.com/googleapis/google-cloud-php](https://github.com/googleapis/google-cloud-php). Any |
| 10 |
support requests, bug reports, or development contributions should be directed to |
| 11 |
that project. |
| 12 |
|
| 13 |
Allows world-wide storage and retrieval of any amount of data at any time. You can use Cloud Storage for a range of |
| 14 |
scenarios including serving website content, storing data for archival and disaster recovery, or distributing large data objects to users via direct download. |
| 15 |
|
| 16 |
### Installation |
| 17 |
|
| 18 |
To begin, install the preferred dependency manager for PHP, [](https://getcomposer.org/Composer](https://getcomposer.org/](https://getcomposer.org/). |
| 19 |
|
| 20 |
Now install this component: |
| 21 |
|
| 22 |
```sh |
| 23 |
$ composer require google/cloud-storage |
| 24 |
``` |
| 25 |
|
| 26 |
### Authentication |
| 27 |
|
| 28 |
Please see our [](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.mdAuthentication guide](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md) for more information |
| 29 |
on authenticating your client. Once authenticated, you'll be ready to start making requests. |
| 30 |
|
| 31 |
### Sample |
| 32 |
|
| 33 |
```php |
| 34 |
require 'vendor/autoload.php'; |
| 35 |
|
| 36 |
use Google\Cloud\Storage\StorageClient; |
| 37 |
|
| 38 |
$storage = new StorageClient(); |
| 39 |
|
| 40 |
$bucket = $storage->bucket('my_bucket'); |
| 41 |
|
| 42 |
// Upload a file to the bucket. |
| 43 |
$bucket->upload( |
| 44 |
fopen('/data/file.txt', 'r') |
| 45 |
); |
| 46 |
|
| 47 |
// Using Predefined ACLs to manage object permissions, you may |
| 48 |
// upload a file and give read access to anyone with the URL. |
| 49 |
$bucket->upload( |
| 50 |
fopen('/data/file.txt', 'r'), |
| 51 |
[ |
| 52 |
'predefinedAcl' => 'publicRead' |
| 53 |
] |
| 54 |
); |
| 55 |
|
| 56 |
// Download and store an object from the bucket locally. |
| 57 |
$object = $bucket->object('file_backup.txt'); |
| 58 |
$object->downloadToFile('/data/file_backup.txt'); |
| 59 |
``` |
| 60 |
|
| 61 |
### Stream Wrapper |
| 62 |
|
| 63 |
```php |
| 64 |
require 'vendor/autoload.php'; |
| 65 |
|
| 66 |
use Google\Cloud\Storage\StorageClient; |
| 67 |
|
| 68 |
$storage = new StorageClient(); |
| 69 |
$storage->registerStreamWrapper(); |
| 70 |
|
| 71 |
$contents = file_get_contents('gs://my_bucket/file_backup.txt'); |
| 72 |
``` |
| 73 |
|
| 74 |
### Version |
| 75 |
|
| 76 |
This component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in |
| 77 |
any minor or patch releases. We will address issues and requests with the highest priority. |
| 78 |
|
| 79 |
### Next Steps |
| 80 |
|
| 81 |
1. Understand the [](https://cloud.google.com/storage/docsofficial documentation](https://cloud.google.com/storage/docs](https://cloud.google.com/storage/docs). |
| 82 |
2. Take a look at [](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/in-depth usage samples](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/). |
| 83 |
|