PHP code example of danilowa / laravel-easy-cloud-storage

1. Go to this page and download the library: Download danilowa/laravel-easy-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/ */

    

danilowa / laravel-easy-cloud-storage example snippets


return [
    'default' => 'local', // Default disk for storage operations.
    'log_errors' => false, // Enable error logging.
    'throw_errors' => false, // Enable exception throwing for errors.
    'disks' => [
        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'), // Root path for local storage.
        ],
        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],
        'google' => [
            'driver' => 'gcs',
            'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'),
            'key_file' => env('GOOGLE_CLOUD_KEY_FILE'),
            'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET'),
            'url' => env('GOOGLE_CLOUD_URL'),
        ],
        // Additional providers can be added as needed.
    ],
];

use Danilowa\LaravelEasyCloudStorage\Facades\EasyStorage;

// Assume $uploadedFile is an instance of UploadedFile, obtained from an HTTP request.
$filePath = EasyStorage::upload($uploadedFile, 'uploads/myfile.txt')
    ->withLog(true)  // Set error logging behavior. Defaults to true if not specified.
    ->withError(false) // Set error handling behavior. Defaults to true if not specified.
    ->setDisk('s3'); // Specify the disk manually instead of using the default.

// Check if the upload was successful
if($filePath === false) {
    return echo "Error uploading the file.";
}

echo "File uploaded successfully: $filePath";


$filePath = EasyStorage::upload($uploadedFile, 'uploads/myfile.txt', 'banana.txt');

// Upload to a specific disk (S3)
$filePathS3 = EasyStorage::upload($uploadedFile, 'uploads/myfile.txt')->setDisk('s3');

return EasyStorage::download('uploads/myfile.txt', 'name.txt')->withLog();

$fileUrl = EasyStorage::url('uploads/myfile.txt');

$deleted = EasyStorage::delete('uploads/myfile.txt');

$exists = EasyStorage::exists('uploads/myfile.txt');

$copied = EasyStorage::copy('uploads/myfile.txt', 'uploads/myfile_copy.txt');

$success = EasyStorage::move('uploads/myfile.txt', 'uploads/newfile.txt');

$size = EasyStorage::size('uploads/myfile.txt');

$lastModified = EasyStorage::lastModified('uploads/myfile.txt');

$metadata = EasyStorage::metadata('uploads/myfile.txt');

$success = EasyStorage::setMetadata('uploads/myfile.txt', [
    'Content-Type' => 'application/pdf',
]);

$files = EasyStorage::list('uploads');

$successPrepend = EasyStorage::prepend('uploads/myfile.txt', 'Header data');
$successAppend = EasyStorage::append('uploads/myfile.txt', 'Footer data');

EasyStorage::createDirectory('uploads/new_directory');
EasyStorage::deleteDirectory('uploads/old_directory');
bash
php artisan vendor:publish --provider="Danilowa\LaravelEasyCloudStorage\EasyCloudStorageServiceProvider"