PHP code example of halalsoft / laravel-google-cloud-storage

1. Go to this page and download the library: Download halalsoft/laravel-google-cloud-storage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

halalsoft / laravel-google-cloud-storage example snippets


'gcs' => [
        'driver'   => 'gcs',
        'key'      => env('GCP_ACCESS_KEY_ID'),
        'secret'   => env('GCP_SECRET_ACCESS_KEY'),
        'bucket'   => env('GCP_BUCKET'),
],

'gcs' => [
        'driver'   => 'gcs',
        'key'      => env('GCP_ACCESS_KEY_ID'),
        'secret'   => env('GCP_SECRET_ACCESS_KEY'),
        'bucket'   => env('GCP_BUCKET'),
        'visibility' => 'public', //Default visibility, you can set public or private
        'url'    => "https://custom.domain.com", //Your public URL (if you use custom domain or CDN)
        'endpoint' => "https://storage.googleapis.com", //Your endpoint URL (if you use custom driver)
        'cache' => [
            'store' => 'memcached',
            'expire' => 600,
            'prefix' => 'cache-prefix',
          ],
],

$disk = Storage::disk('gcs');

// create a file
$disk->put('avatars/1', $request->file("image"));

// check if a file exists
$exists = $disk->exists('image.jpg');

// get file last modification date
$time = $disk->lastModified('image1.jpg');

// copy a file
$disk->copy('old/image1.jpg', 'new/image1.jpg');

// move a file
$disk->move('old/image1.jpg', 'new/image1.jpg');

// get url to file
$url = $disk->url('avatar/yaskur.jpg');