unioil-loyalty-app/app/Libraries/S3.php

42 lines
1.0 KiB
PHP
Executable File

<?php
namespace App\Libraries;
use Illuminate\Contracts\Filesystem\Filesystem;
class S3
{
public function __construct()
{
}
public function upload($image, $folder, $filename = null)
{
if($filename != null)
$imageFileName = $filename . '.' . $image->getClientOriginalExtension();
else
$imageFileName = time() . '.' . $image->getClientOriginalExtension();
$s3 = \Storage::disk('s3');
$filePath = '/'.env('AWS_BUCKET_ENV').'/'.$folder.'/'.$imageFileName;
$s3->put($filePath, file_get_contents($image));
return $filePath;
}
public static function public_path($path)
{
if(env('S3_FORMAT_VERSION') == 2)
return 'https://s3-'.env('AWS_DEFAULT_REGION').'.amazonaws.com/'.env('AWS_BUCKET').$path;
else
return 'https://'.env('AWS_BUCKET').'.s3-'.env('AWS_DEFAULT_REGION').'.amazonaws.com'.$path;
}
public function remove_public_path($url)
{
$remove = 'https://'.env('AWS_BUCKET').'.s3-'.env('AWS_DEFAULT_REGION').'.amazonaws.com';
return str_replace($remove, '', $url);
}
}