109 lines
2.2 KiB
PHP
109 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Core;
|
|
|
|
use Illuminate\Support\Facades\Storage as Storage2;
|
|
use Symfony\Component\Process\Exception\ProcessFailedException;
|
|
use Symfony\Component\Process\Process;
|
|
|
|
class Storage
|
|
{
|
|
public static function checkDirOrCreate($dir)
|
|
{
|
|
return self::checkDir($dir) ? true : self::createDir($dir);
|
|
}
|
|
|
|
public static function checkDir($dir)
|
|
{
|
|
return Storage2::disk('local')->has($dir);
|
|
}
|
|
|
|
public static function move($source, $target)
|
|
{
|
|
return Storage2::move($source, $target);
|
|
}
|
|
|
|
public static function copy($source, $target)
|
|
{
|
|
return Storage2::copy($source, $target);
|
|
}
|
|
|
|
public static function checkFile($file)
|
|
{
|
|
return Storage2::exists($file);
|
|
}
|
|
|
|
public static function createDir($dir)
|
|
{
|
|
Storage2::makeDirectory($dir);
|
|
|
|
return true;
|
|
}
|
|
|
|
public static function deleteDir($dir)
|
|
{
|
|
Storage2::deleteDirectory($dir);
|
|
|
|
return true;
|
|
}
|
|
|
|
public static function deleteFile($file)
|
|
{
|
|
Storage2::delete($file);
|
|
|
|
return true;
|
|
}
|
|
|
|
public static function secureDeleteFile($file)
|
|
{
|
|
$process = new Process(['srm', $file]);
|
|
$process->run();
|
|
|
|
if (! $process->isSuccessful()) {
|
|
throw new ProcessFailedException($process);
|
|
}
|
|
}
|
|
|
|
public static function createFile($file, $content)
|
|
{
|
|
Storage2::put($file, $content);
|
|
}
|
|
|
|
public static function getFile($file)
|
|
{
|
|
return Storage2::get($file);
|
|
}
|
|
|
|
public static function getFilesize($file)
|
|
{
|
|
return Storage2::size($file);
|
|
}
|
|
|
|
public static function getUrlFile($file)
|
|
{
|
|
return Storage2::url($file);
|
|
}
|
|
|
|
public static function download($file, $name = false, $headers = false)
|
|
{
|
|
return Storage2::download($file, $name, $headers);
|
|
}
|
|
|
|
public static function getPublicPath($file = false)
|
|
{
|
|
return public_path($file);
|
|
}
|
|
|
|
public static function getFileType($file)
|
|
{
|
|
$file = self::getStoragePath().$file;
|
|
|
|
return File::getFileType($file);
|
|
}
|
|
|
|
public static function getStoragePath($file = false)
|
|
{
|
|
return storage_path($file);
|
|
}
|
|
}
|