84 lines
2.7 KiB
PHP
84 lines
2.7 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use Storage;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
class SpaceController extends Controller
|
||
|
{
|
||
|
//
|
||
|
public static function getEnv()
|
||
|
{
|
||
|
$env = env('APP_ENV', 'development');
|
||
|
return ( $env == 'development' || $env == 'local' ) ? 'dev' : 'prod';
|
||
|
}
|
||
|
|
||
|
public static function uploadFile($file, $processName, $data)
|
||
|
{
|
||
|
$ext = $file->getClientOriginalExtension();
|
||
|
$typeFile = self::getEnv();
|
||
|
|
||
|
switch ( $processName ) {
|
||
|
case 'dokumen' :
|
||
|
$fileName = 'Dokumen_'.date('Ymd')."_".date('His').'.'.$ext;
|
||
|
Storage::putFileAs($typeFile . '/dokumen', $file, $fileName);
|
||
|
$disk = '/dokumen/' . $fileName;
|
||
|
break;
|
||
|
case 'meeting':
|
||
|
$fileName = 'dok_'.date('Ymd')."_".date('His').'.'.$ext;
|
||
|
Storage::putFileAs($typeFile . '/dokumen', $file, $fileName);
|
||
|
$disk = '/dok_meeting/' . $fileName;
|
||
|
break;
|
||
|
case 'logo':
|
||
|
$fileName = 'Logo_'.date('Ymd')."_".date('His').'.'.$ext;
|
||
|
Storage::putFileAs($typeFile . '/gallery', $file, $fileName);
|
||
|
$disk = '/gallery/' . $fileName;
|
||
|
break;
|
||
|
case 'profile':
|
||
|
$fileName = 'User_'.date('Ymd')."_".date('His').'.'.$ext;
|
||
|
Storage::putFileAs($typeFile . '/gallery', $file, $fileName);
|
||
|
$disk = '/gallery/' . $fileName;
|
||
|
break;
|
||
|
case 'client':
|
||
|
$fileName = 'Client_'.date('Ymd')."_".date('His').'.'.$ext;
|
||
|
Storage::putFileAs($typeFile . '/gallery', $file, $fileName);
|
||
|
$disk = '/gallery/' . $fileName;
|
||
|
break;
|
||
|
case 'user':
|
||
|
$fileName = 'User_'.date('Ymd')."_".date('His').'.'.$ext;
|
||
|
Storage::putFileAs($typeFile . '/gallery', $file, $fileName);
|
||
|
$disk = '/gallery/' . $fileName;
|
||
|
break;
|
||
|
}
|
||
|
return $disk;
|
||
|
}
|
||
|
|
||
|
public static function checkFileIfExists($urlDoc)
|
||
|
{
|
||
|
$typeFile = self::getEnv();
|
||
|
return Storage::exists($typeFile . $urlDoc);
|
||
|
}
|
||
|
|
||
|
public static function deleteFile($urlDoc)
|
||
|
{
|
||
|
if (self::checkFileIfExists($urlDoc)) {
|
||
|
$typeFile = self::getEnv();
|
||
|
Storage::delete($typeFile . $urlDoc);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static function getFile($urlDoc, $expiredTime = null)
|
||
|
{
|
||
|
$typeFile = self::getEnv();
|
||
|
$expiredTime = is_null($expiredTime) ? now()->addDay(1) : $expiredTime;
|
||
|
return Storage::temporaryUrl($typeFile . $urlDoc, $expiredTime);
|
||
|
}
|
||
|
|
||
|
public static function downloadFile($urlDoc)
|
||
|
{
|
||
|
$typeFile = self::getEnv();
|
||
|
return Storage::download($typeFile . $urlDoc);
|
||
|
}
|
||
|
}
|