mein-sterntours/app/Http/Controllers/FileController.php

136 lines
4.2 KiB
PHP
Executable file

<?php
namespace App\Http\Controllers;
use Response;
use Storage;
class FileController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct() {}
public function show($id = null, $disk = null, $do = 'file')
{
$path = "";
$filename = "";
switch ($disk) {
case 'customer':
$file = \App\Models\CustomerFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
break;
case 'travel_user':
$file = \App\Models\CustomerFewoFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
break;
case 'booking':
$file = \App\Models\BookingFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
break;
case 'general':
$file = \App\Models\GeneralFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
break;
case 'booking_fewo':
$file = \App\Models\TravelUserBookingFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
break;
case 'lead':
$file = \App\Models\LeadFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
break;
case 'cms_file':
$file = \App\Models\CMSContent::findOrFail($id);
$filename = $file->name;
$path = $file->getPath();
break;
case 'booking_document':
$file = \App\Models\BookingDocument::findOrFail($id);
$filename = $file->name;
$path = $file->getPath();
break;
}
if (file_exists($path)) {
// Cache-Control Header für PDFs und andere Dateien, die sich häufig ändern
$headers = [
'Cache-Control' => 'no-cache, no-store, must-revalidate',
'Pragma' => 'no-cache',
'Expires' => '0'
];
switch ($do) {
case 'file':
return Response::file($path, $headers);
break;
case 'download':
return Response::download($path, $filename, $headers);
break;
case 'url':
return $path . $filename;
break;
}
}
}
public function showExpert($type = null, $class = null, $year = null, $file = null, $do = null)
{
/*if ($type == 'xls') {
$path = storage_path("app/export/");
$filename = $file . '.xls';
}*/
$path = "";
$filename = "";
$headers = [
'Cache-Control' => 'no-cache, no-store, must-revalidate',
'Pragma' => 'no-cache',
'Expires' => '0'
];
if ($class === 'invoices' || $class === 'infos') {
$headers = [
'Content-Type: application/pdf',
'Pragma: no-cache',
'Cache-Control: no-store,no-cache, must-revalidate, post-check=0, pre-check=0'
];
$dir = $year . "/";
$filename = $file;
if ($type === 'fewo') {
if (Storage::disk('fewo_invoices')->exists($dir . $filename)) {
$path = Storage::disk('fewo_invoices')->path($dir . $filename);
}
}
if ($type === 'fewo') {
if (Storage::disk('fewo_infos')->exists($dir . $filename)) {
$path = Storage::disk('fewo_infos')->path($dir . $filename);
}
}
}
if (file_exists($path)) {
if ($do === "download") {
return Response::download($path, $filename, $headers);
}
if ($do === "file") {
return Response::file($path, $headers);
}
}
}
}