Local file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
private function save_s3($path){ if(is_s3($path) == true){ return true; } $file_path = public_path($path); $file = File::get($file_path); //$file_name = basename($path); $result = Storage::disk('s3')->put($path, $file, 'public'); if($result != true){ return false; }else{ return true; } } |
Other related helper functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
if(!function_exists('s3_url')){ function s3_url($path){ if(is_s3($path) == true){ return $path; } return 'https://topeak-img.s3.eu-central-1.amazonaws.com' . $path; } } if(!function_exists('is_s3')){ function is_s3($url){ $pattern = '/(s3-|s3\.)?(.*)\.amazonaws\.com/'; preg_match($pattern, $url, $match); if($match == false){ return false; } return true; } } |