Add new version in repository
This commit is contained in:
73
app/Repositories/Core/File.php
Normal file
73
app/Repositories/Core/File.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
use SoftCreatR\MimeDetector\MimeDetector;
|
||||
use SoftCreatR\MimeDetector\MimeDetectorException;
|
||||
|
||||
class File
|
||||
{
|
||||
public static function checkDirOrCreate($dir)
|
||||
{
|
||||
return self::checkDir($dir) ? true : self::createDir($dir);
|
||||
}
|
||||
|
||||
public static function checkDir($dir)
|
||||
{
|
||||
// File::isDirectory($path)
|
||||
return is_dir($dir);
|
||||
}
|
||||
|
||||
public static function checkFile($file)
|
||||
{
|
||||
return file_exists($file);
|
||||
}
|
||||
|
||||
public static function createDir($dir)
|
||||
{
|
||||
Storage::makeDirectory($dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function deleteDir($dir)
|
||||
{
|
||||
Storage::deleteDirectory($dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function createFile($file, $content)
|
||||
{
|
||||
Storage::put($file, $content);
|
||||
}
|
||||
|
||||
public static function getFile($file)
|
||||
{
|
||||
return Storage::get($file);
|
||||
}
|
||||
|
||||
public static function getFilesize($file)
|
||||
{
|
||||
return Storage::size($file);
|
||||
}
|
||||
|
||||
public static function getUrlFile($file)
|
||||
{
|
||||
return Storage::url($file);
|
||||
}
|
||||
|
||||
public static function download($file, $name = false, $headers = false)
|
||||
{
|
||||
return Storage::download($file, $name, $headers);
|
||||
}
|
||||
|
||||
public static function getFileType($file)
|
||||
{
|
||||
try {
|
||||
return (new MimeDetector())->setFile($file)->getFileType();
|
||||
} catch (MimeDetectorException $e) {
|
||||
die('An error occured while trying to load the given file.');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user