Fix: Tour-Titelbild wird gespeichert und angezeigt
This commit is contained in:
parent
3570f6a8ed
commit
ae7bab1c95
6 changed files with 77 additions and 8 deletions
|
|
@ -83,6 +83,21 @@ class TourController
|
|||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
if (!empty($_FILES['bild']['name'])) {
|
||||
try {
|
||||
Image::storePublic($_FILES['bild'], 'img/tour', (string) $tour->id);
|
||||
} catch (\Throwable $e) {
|
||||
if (!$e instanceof \RuntimeException) {
|
||||
error_log('Tourbild-Upload: ' . $e);
|
||||
}
|
||||
|
||||
flash_set('error', $e instanceof \RuntimeException
|
||||
? $e->getMessage()
|
||||
: 'Das Bild konnte nicht verarbeitet werden.');
|
||||
redirect('/tour/' . $tour->id . '/edit');
|
||||
}
|
||||
}
|
||||
|
||||
redirect('/tour');
|
||||
}
|
||||
|
||||
|
|
@ -190,7 +205,8 @@ class TourController
|
|||
|
||||
if (!empty($_FILES['bild']['name'])) {
|
||||
try {
|
||||
Image::store($_FILES['bild'], 'tour_' . $tourId, (string) input('name'));
|
||||
// Tour-Titelbilder liegen wie bisher unter public/img/tour/<id>.jpg
|
||||
Image::storePublic($_FILES['bild'], 'img/tour', (string) $tourId);
|
||||
} catch (\Throwable $e) {
|
||||
if (!$e instanceof \RuntimeException) {
|
||||
error_log('Tourbild-Upload: ' . $e);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,29 @@ class Image
|
|||
* lesbar oder das Zielverzeichnis nicht beschreibbar ist
|
||||
*/
|
||||
public static function store(array $upload, string $category, string $name): bool
|
||||
{
|
||||
$dir = config('paths.img_storage') . '/' . self::slug($category);
|
||||
|
||||
return self::storeTo($upload, $dir, self::slug(pathinfo($name, PATHINFO_FILENAME)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert ein öffentlich ausgeliefertes Bild unter public/<directory>/.
|
||||
* Wird für die Tour-Titelbilder (public/img/tour/<id>.jpg) verwendet.
|
||||
*/
|
||||
public static function storePublic(array $upload, string $directory, string $name): bool
|
||||
{
|
||||
$dir = public_path(trim($directory, '/'));
|
||||
|
||||
return self::storeTo($upload, $dir, self::slug(pathinfo($name, PATHINFO_FILENAME)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gemeinsame Prüf- und Speicherlogik für alle Zielverzeichnisse.
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
private static function storeTo(array $upload, string $dir, string $baseName): bool
|
||||
{
|
||||
// Ohne JPEG-Unterstützung in GD schlägt imagejpeg() sonst mit einem
|
||||
// Fatal Error fehl, der (ohne display_errors) unsichtbar bleibt.
|
||||
|
|
@ -67,8 +90,6 @@ class Image
|
|||
throw new \RuntimeException('Das Bild hat keine gültige Größe.');
|
||||
}
|
||||
|
||||
$dir = config('paths.img_storage') . '/' . self::slug($category);
|
||||
|
||||
if (!is_dir($dir)) {
|
||||
// 0775 genügt, wenn PHP-FPM als Eigentümer/Gruppe läuft; 0777 hilft
|
||||
// bei Bind-Mounts mit abweichender UID.
|
||||
|
|
@ -79,7 +100,7 @@ class Image
|
|||
throw new \RuntimeException('Der Bildspeicher auf dem Server ist nicht beschreibbar. Bitte den Administrator informieren.');
|
||||
}
|
||||
|
||||
$base = $dir . '/' . self::slug(pathinfo($name, PATHINFO_FILENAME));
|
||||
$base = $dir . '/' . $baseName;
|
||||
|
||||
$data = @file_get_contents($tmp);
|
||||
$src = $data === false ? false : @imagecreatefromstring($data);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,15 @@
|
|||
<div class="form-group" style="display:flex;">
|
||||
<label class="ml-2 mt-4" style="width:150px; text-align:left;" for="bild"><h4>Bild:</h4></label>
|
||||
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php $tourThumb = public_path('img/tour/' . (int) $tour->id . '.jpg'); ?>
|
||||
<?php if (is_file($tourThumb)): ?>
|
||||
<a href="/img/tour/<?= e($tour->id) ?>_gross.jpg?v=<?= @filemtime(public_path('img/tour/' . (int) $tour->id . '_gross.jpg')) ?>"
|
||||
data-lightbox="<?= e($tour->id) ?>_gross.jpg" data-title="<?= e($tour->name) ?>">
|
||||
<img src="/img/tour/<?= e($tour->id) ?>.jpg?v=<?= @filemtime($tourThumb) ?>" class="mt-3 ml-3">
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php endif; ?>
|
||||
|
||||
<input type="file" class="mt-3 mr-2 form-control" id="bild" style="font-size:20px;"
|
||||
name="bild" value="">
|
||||
|
|
|
|||
|
|
@ -24,7 +24,15 @@
|
|||
<div class="form-group" style="display:flex;">
|
||||
<label class="ml-2 mt-4" style="width:150px; text-align:left;" for="bild"><h4>Bild:</h4></label>
|
||||
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php $tourThumb = public_path('img/tour/' . (int) $tour->id . '.jpg'); ?>
|
||||
<?php if (is_file($tourThumb)): ?>
|
||||
<a href="/img/tour/<?= e($tour->id) ?>_gross.jpg?v=<?= @filemtime(public_path('img/tour/' . (int) $tour->id . '_gross.jpg')) ?>"
|
||||
data-lightbox="<?= e($tour->id) ?>_gross.jpg" data-title="<?= e($tour->name) ?>">
|
||||
<img src="/img/tour/<?= e($tour->id) ?>.jpg?v=<?= @filemtime($tourThumb) ?>" class="mt-3 ml-3">
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php endif; ?>
|
||||
|
||||
<input type="file" class="mt-3 mr-2 form-control" id="bild" style="font-size:20px;" name="bild" value="">
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -65,7 +65,15 @@
|
|||
<label>Du nimmst nicht teil.</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php $tourThumb = public_path('img/tour/' . (int) $tour->id . '.jpg'); ?>
|
||||
<?php if (is_file($tourThumb)): ?>
|
||||
<a href="/img/tour/<?= e($tour->id) ?>_gross.jpg?v=<?= @filemtime(public_path('img/tour/' . (int) $tour->id . '_gross.jpg')) ?>"
|
||||
data-lightbox="<?= e($tour->id) ?>_gross.jpg" data-title="<?= e($tour->name) ?>">
|
||||
<img src="/img/tour/<?= e($tour->id) ?>.jpg?v=<?= @filemtime($tourThumb) ?>" class="mt-3 ml-3">
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="mt-1" style="display:flex;">
|
||||
<label class="ml-2" style="width:140px; text-align:left;font-size:18px;" for="is_cancelled">Storniert:</label>
|
||||
|
|
|
|||
|
|
@ -40,7 +40,15 @@
|
|||
<label>Du nimmst nicht teil.</label>
|
||||
<?php endif; ?>
|
||||
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php $tourThumb = public_path('img/tour/' . (int) $tour->id . '.jpg'); ?>
|
||||
<?php if (is_file($tourThumb)): ?>
|
||||
<a href="/img/tour/<?= e($tour->id) ?>_gross.jpg?v=<?= @filemtime(public_path('img/tour/' . (int) $tour->id . '_gross.jpg')) ?>"
|
||||
data-lightbox="<?= e($tour->id) ?>_gross.jpg" data-title="<?= e($tour->name) ?>">
|
||||
<img src="/img/tour/<?= e($tour->id) ?>.jpg?v=<?= @filemtime($tourThumb) ?>" class="mt-3 ml-3">
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="mt-1">
|
||||
<label class="ml-2" style="width:140px; text-align:left;font-size:18px;" for="beschreibung">Beschreibung:</label>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue