mein-sterntours/app/Http/Controllers/FileController.php
2021-05-07 17:44:02 +02:00

115 lines
No EOL
3.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 = "";
if ($disk === 'customer'){
$file = \App\Models\CustomerFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
}
if ($disk === 'travel_user'){
$file = \App\Models\CustomerFewoFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
}
if ($disk === 'booking'){
$file = \App\Models\BookingFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
}
if ($disk === 'general'){
$file = \App\Models\GeneralFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
}
if ($disk === 'booking_fewo'){
$file = \App\Models\TravelUserBookingFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
}
if ($disk === 'lead'){
$file = \App\Models\LeadFile::findOrFail($id);
$filename = $file->original_name;
$path = $file->getPath();
}
if ($disk === 'cms_file'){
$file = \App\Models\CMSContent::findOrFail($id);
$filename = $file->name;
$path = $file->getPath();
}
if (file_exists($path)) {
if($do === "download"){
return Response::download($path, $filename);
}
return Response::file($path);
}
}
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 = [];
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);
}
}
}
}