Mache Medien, Übungen und Kurse in der Verwaltung bearbeitbar.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
4f2e5a5f3b
commit
3ee9f529ca
33 files changed
+1105
-284
No files matched your search
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
|
||||
class IncomingFile
|
||||
{
|
||||
public static function store(mixed $value): ?string
|
||||
{
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $item) {
|
||||
$stored = self::store($item);
|
||||
|
||||
if ($stored !== null) {
|
||||
return $stored;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($value instanceof TemporaryUploadedFile || $value instanceof UploadedFile) {
|
||||
$extension = strtolower($value->getClientOriginalExtension());
|
||||
$stem = preg_replace('/[^A-Za-z0-9_-]+/', '-', pathinfo($value->getClientOriginalName(), PATHINFO_FILENAME)) ?? '';
|
||||
$stem = trim($stem, '-');
|
||||
$stem = ($stem !== '' ? $stem : 'datei').'-'.bin2hex(random_bytes(4));
|
||||
|
||||
if (preg_match('/^[a-z0-9]{1,8}$/', $extension) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$path = $value->storeAs('inhalte', $stem.'.'.$extension, 'cms_incoming');
|
||||
|
||||
return is_string($path) && $path !== '' ? $path : null;
|
||||
}
|
||||
|
||||
if (! is_string($value) || $value === '' || str_contains($value, '..') || ! str_starts_with($value, 'inhalte/')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Storage::disk('cms_incoming')->exists($value) ? $value : null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user