Fixed tour image upload
This commit is contained in:
parent
0d24674dfb
commit
a1c41d08ca
6 changed files with 31 additions and 50 deletions
|
|
@ -12,7 +12,6 @@
|
||||||
use Intervention\Image\Facades\Image;
|
use Intervention\Image\Facades\Image;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class TourController extends Controller
|
class TourController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -114,6 +113,10 @@
|
||||||
$tour->is_cancelled = $request->input('is_cancelled', false);
|
$tour->is_cancelled = $request->input('is_cancelled', false);
|
||||||
$tour->save();
|
$tour->save();
|
||||||
|
|
||||||
|
if ($request->hasFile('bild')) {
|
||||||
|
$this->storeTourImage($request->bild, $tour->id);
|
||||||
|
}
|
||||||
|
|
||||||
Log::info("Stored deadline:" . $tour->deadline);
|
Log::info("Stored deadline:" . $tour->deadline);
|
||||||
|
|
||||||
return redirect('/tour');
|
return redirect('/tour');
|
||||||
|
|
@ -295,31 +298,8 @@
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($request->bild) {
|
if ($request->hasFile('bild')) {
|
||||||
$this->storeImage($request->bild, "tour_".$tour->id, $request->name);
|
$this->storeTourImage($request->bild, $tour->id);
|
||||||
/*
|
|
||||||
Log::info("Processing image");
|
|
||||||
$bild = Image::make($request->bild);
|
|
||||||
$breite = $bild->width();
|
|
||||||
$hoehe = $bild->height();
|
|
||||||
if ($breite > $hoehe) {
|
|
||||||
Image::make($request->bild)
|
|
||||||
->widen(1200)
|
|
||||||
->save(public_path() . '/img/tour/' . $tour->id . '_gross.jpg');
|
|
||||||
Image::make($request->bild)
|
|
||||||
->widen(64)
|
|
||||||
->save(public_path() . '/img/tour/' . $tour->id . '.jpg');
|
|
||||||
} else {
|
|
||||||
Image::make($request->bild)
|
|
||||||
->heighten(900)
|
|
||||||
->save(public_path() . '/img/tour/' . $tour->id . '_gross.jpg');
|
|
||||||
Image::make($request->bild)
|
|
||||||
->widen(96)
|
|
||||||
->save(public_path() . '/img/tour/' . $tour->id . '.jpg');
|
|
||||||
}
|
|
||||||
Log::info("Image saved as ". public_path() . '/img/tour/' . $tour->id . '_gross.jpg');
|
|
||||||
Log::info("Image saved as ". public_path() . '/img/tour/' . $tour->id . '.jpg');
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -447,35 +427,34 @@
|
||||||
return response()->file(public_path()."/img/placeholder/icon_unknown.png");
|
return response()->file(public_path()."/img/placeholder/icon_unknown.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function storeImage($bild, $category, $name) {
|
private function storeTourImage($bild, $tourId) {
|
||||||
$cat=Str::slug($category);
|
// The tour thumbnail is displayed from public/img/tour, so it has to be
|
||||||
$name=Str::slug($name);
|
// stored there (and not in the gallery directory under storage/).
|
||||||
|
$dirPath = public_path('img/tour');
|
||||||
$dirPath = storage_path() . "/img_storage/$cat";
|
|
||||||
if (!file_exists($dirPath)) {
|
if (!file_exists($dirPath)) {
|
||||||
mkdir($dirPath, 0777, true);
|
mkdir($dirPath, 0777, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$bild = Image::make($bild);
|
$image = Image::make($bild);
|
||||||
$breite = $bild->width();
|
$breite = $image->width();
|
||||||
$hoehe = $bild->height();
|
$hoehe = $image->height();
|
||||||
if ($breite > $hoehe) {
|
if ($breite > $hoehe) {
|
||||||
Image::make($bild)
|
Image::make($bild)
|
||||||
->widen(1200)
|
->widen(1200)
|
||||||
->save("$dirPath/$name"."_gross.jpg");
|
->save("$dirPath/{$tourId}_gross.jpg");
|
||||||
Image::make($bild)
|
Image::make($bild)
|
||||||
->widen(64)
|
->widen(64)
|
||||||
->save("$dirPath/$name".".jpg");
|
->save("$dirPath/{$tourId}.jpg");
|
||||||
} else {
|
} else {
|
||||||
Image::make($bild)
|
Image::make($bild)
|
||||||
->heighten(900)
|
->heighten(900)
|
||||||
->save("$dirPath/$name"."_gross.jpg");;
|
->save("$dirPath/{$tourId}_gross.jpg");
|
||||||
Image::make($bild)
|
Image::make($bild)
|
||||||
->widen(96)
|
->widen(96)
|
||||||
->save("$dirPath/$name".".jpg");
|
->save("$dirPath/{$tourId}.jpg");
|
||||||
}
|
}
|
||||||
Log::info("Image saved as $dirPath/$name" . '_gross.jpg');
|
Log::info("Image saved as $dirPath/{$tourId}_gross.jpg");
|
||||||
Log::info("Image saved as $dirPath/$name" . '.jpg');
|
Log::info("Image saved as $dirPath/{$tourId}.jpg");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@
|
||||||
|
|
||||||
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
||||||
<!--File exists -->
|
<!--File exists -->
|
||||||
<a href="/img/user/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
<a href="/img/tour/{{$tour->id}}_gross.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'_gross.jpg')) }}" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
||||||
<img src="/img/user/{{$tour->id}}.jpg" class="mt-3 ml-3" >
|
<img src="/img/tour/{{$tour->id}}.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'.jpg')) }}" class="mt-3 ml-3" >
|
||||||
</a>
|
</a>
|
||||||
@else
|
@else
|
||||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3" >
|
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3" >
|
||||||
|
|
|
||||||
|
|
@ -59,9 +59,10 @@
|
||||||
|
|
||||||
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
||||||
<!--File exists -->
|
<!--File exists -->
|
||||||
<a href="/img/tour/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg"
|
<a href="/img/tour/{{$tour->id}}_gross.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'_gross.jpg')) }}"
|
||||||
|
data-lightbox="{{$tour->id}}_gross.jpg"
|
||||||
data-title="{{ $tour->name }}">
|
data-title="{{ $tour->name }}">
|
||||||
<img src="/img/tour/{{$tour->id}}.jpg" class="mt-3 ml-3">
|
<img src="/img/tour/{{$tour->id}}.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'.jpg')) }}" class="mt-3 ml-3">
|
||||||
</a>
|
</a>
|
||||||
@else
|
@else
|
||||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,8 @@
|
||||||
|
|
||||||
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
||||||
<!--File exists -->
|
<!--File exists -->
|
||||||
<a href="/img/user/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
<a href="/img/tour/{{$tour->id}}_gross.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'_gross.jpg')) }}" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
||||||
<img src="/img/user/{{$tour->id}}.jpg" class="mt-3 ml-3" >
|
<img src="/img/tour/{{$tour->id}}.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'.jpg')) }}" class="mt-3 ml-3" >
|
||||||
</a>
|
</a>
|
||||||
@else
|
@else
|
||||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3" >
|
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3" >
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,10 @@
|
||||||
|
|
||||||
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
||||||
<!--File exists -->
|
<!--File exists -->
|
||||||
<a href="/img/tour/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg"
|
<a href="/img/tour/{{$tour->id}}_gross.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'_gross.jpg')) }}"
|
||||||
|
data-lightbox="{{$tour->id}}_gross.jpg"
|
||||||
data-title="{{ $tour->name }}">
|
data-title="{{ $tour->name }}">
|
||||||
<img src="/img/tour/{{$tour->id}}.jpg" class="mt-3 ml-3">
|
<img src="/img/tour/{{$tour->id}}.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'.jpg')) }}" class="mt-3 ml-3">
|
||||||
</a>
|
</a>
|
||||||
@else
|
@else
|
||||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@
|
||||||
|
|
||||||
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
||||||
<!--File exists -->
|
<!--File exists -->
|
||||||
<a href="/img/tour/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
<a href="/img/tour/{{$tour->id}}_gross.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'_gross.jpg')) }}" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
||||||
<img src="/img/user/{{$tour->id}}.jpg" class="mt-3 ml-3" >
|
<img src="/img/tour/{{$tour->id}}.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'.jpg')) }}" class="mt-3 ml-3" >
|
||||||
</a>
|
</a>
|
||||||
@else
|
@else
|
||||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3" >
|
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3" >
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue