You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

62 lines
1.5 KiB

<?php
namespace App\Extends;
use App\Models\File;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class FileDB {
/**
* File uploaded
* @var Object
*/
protected $file;
/**
* @param Object
*/
public function __construct($file = NULL)
{
$this->file = $file;
}
public static function save($file) {
if(is_null($file)) $file = $this->file;
if(!is_null($file)) {
$id = uniqid();
File::create([
'id' => $id,
'name' => $file->getClientOriginalName(),
'data' => base64_encode(gzcompress($file->get())),
'ext' => $file->extension(),
'contentType' => $file->getClientMimeType(),
'created_by' => Auth::user()->id,
'organization_id' => Auth::user()->organization_id
]);
return $id;
}
return null;
}
public static function get($id) {
$file = File::findOrFail($id);
return $file;
}
public static function show($id) {
try {
$media = File::findOrFail($id);
#$img_type = ['image/jpg','image/jpeg','image/gif','image/png','image/webp'];
#$video_type = ['video/mp4'];
if(!is_null($media)) {
return response( gzuncompress(base64_decode($media->data)) )
->header('Content-Type', $media->contentType);
} else {
return abort(404);
}
}
catch(Exception $e) {
return abort(404);
}
}
}