95 lines
No EOL
3.1 KiB
PHP
95 lines
No EOL
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Storage;
|
|
use Response;
|
|
use App\Services\Credit;
|
|
use App\Services\Invoice;
|
|
|
|
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 === 'user'){
|
|
$file = \App\Models\File::findOrFail($id);
|
|
$path = Storage::disk($disk)->path($file->dir.$file->filename);
|
|
if (file_exists($path)) {
|
|
return Response::file($path);
|
|
}
|
|
}
|
|
|
|
|
|
if ($disk === 'invoice'){
|
|
$shopping_order = \App\Models\ShoppingOrder::findOrFail($id);
|
|
$filename = Invoice::getFilename($shopping_order);
|
|
$path = Invoice::getDownloadPath($shopping_order);
|
|
if (!Storage::disk('public')->exists($path)) {
|
|
return Response::make('File no found.', 404);
|
|
}
|
|
$file = Storage::disk('public')->get($path);
|
|
$type = Storage::disk('public')->mimeType($path);
|
|
|
|
if($do === 'download'){
|
|
return Response::make($file, 200)
|
|
->header("Content-Type", $type)
|
|
->header('Content-disposition', 'attachment; filename="'.$filename.'"');
|
|
/* $full_path = Invoice::getDownloadPath($shopping_order, true);
|
|
$he
|
|
if (file_exists($full_path)) {
|
|
return Response::download($full_path, $filename);
|
|
}*/
|
|
}
|
|
if($do === 'stream'){
|
|
return Response::make($file, 200)
|
|
->header("Content-Type", $type)
|
|
->header('Content-disposition','filename="'.$filename.'"');
|
|
}
|
|
|
|
}
|
|
|
|
if ($disk === 'credit'){
|
|
$UserCredit = \App\Models\UserCredit::findOrFail($id);
|
|
$filename = Credit::getFilename($UserCredit);
|
|
$path = Credit::getDownloadPath($UserCredit);
|
|
if (!Storage::disk('public')->exists($path)) {
|
|
return Response::make('File no found.', 404);
|
|
}
|
|
$file = Storage::disk('public')->get($path);
|
|
$type = Storage::disk('public')->mimeType($path);
|
|
|
|
if($do === 'download'){
|
|
return Response::make($file, 200)
|
|
->header("Content-Type", $type)
|
|
->header('Content-disposition', 'attachment; filename="'.$filename.'"');
|
|
/* $full_path = Invoice::getDownloadPath($shopping_order, true);
|
|
$he
|
|
if (file_exists($full_path)) {
|
|
return Response::download($full_path, $filename);
|
|
}*/
|
|
}
|
|
if($do === 'stream'){
|
|
return Response::make($file, 200)
|
|
->header("Content-Type", $type)
|
|
->header('Content-disposition','filename="'.$filename.'"');
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |