You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
<?php
|
|
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
|
|
|
if (! function_exists('asset_static')) {
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
function asset_static(string $path, $time = null, $options = []): bool|string
|
|
{
|
|
if ($path === '') {
|
|
throw new Exception(__('domains/system/messages.backup.path_required'));
|
|
}
|
|
|
|
if ($time === null) {
|
|
$time = now()->addMinutes(5);
|
|
}
|
|
|
|
if (Storage::disk('local')->exists($path)) {
|
|
return url(Storage::temporaryUrl($path, $time, $options));
|
|
}
|
|
|
|
if (Storage::disk('public')->exists($path)) {
|
|
return url(Storage::url($path));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (! function_exists('upload_file')) {
|
|
function upload_file(UploadedFile|TemporaryUploadedFile $file, string $path, string $disk = 'local'): bool|string
|
|
{
|
|
return $file->store($path, $disk);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('remove_file')) {
|
|
function remove_file(string $path): void
|
|
{
|
|
if (Storage::disk('local')->exists($path)) {
|
|
Storage::disk('local')->delete($path);
|
|
}
|
|
if (Storage::disk('public')->exists($path)) {
|
|
Storage::disk('public')->delete($path);
|
|
}
|
|
}
|
|
}
|
|
|