FEATURE #1417: add uploaded files overview

This commit is contained in:
Michal Kváček
2016-02-08 16:06:44 +01:00
parent e98032a3e1
commit bd38e3fd98
7 changed files with 159 additions and 5 deletions
+66
View File
@@ -0,0 +1,66 @@
<?php
namespace App\Helpers;
use App\Models\File;
class FileManager
{
/**
* @param File $file
*
* @return \Illuminate\Contracts\Routing\UrlGenerator|string
*/
public static function getPreview(File $file)
{
list($type, $subtype) = explode('/', $file->mime_type);
switch ($type) {
case 'image':
// try to check if file have thumbnail
if (file_exists(config('app.thumbnail_url') . '/' . $file->filename)) {
$url = config('app.thumbnail_url') . '/' . $file->filename;
} else {
$url = config('app.upload_url') . '/' . $file->filename;
}
return '<img src="' . $url . '" alt="' . $file->description . '" />';
break;
case 'text':
return '<i class="fa fa-file-text-o"></i>';
break;
case 'application':
switch ($subtype) {
case 'pdf':
return '<i class="fa fa-file-pdf-o"></i>';
break;
default:
return '<i class="fa fa-newspaper-o"></i>';
break;
}
break;
default:
return '<i class="fa fa-question"></i>';
break;
}
}
/**
*
*
* @param File $file
*
* @return string
*/
public static function getFormattedSize(File $file)
{
$bytes = $file->file_size;
$label = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
for ($i = 0; $bytes >= 1024 && $i < (count($label) - 1); $bytes /= 1024, $i++) {
;
}
return (round($bytes, 2) . " " . $label[$i]);
}
}