You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
<?php
|
|
namespace App\Helper;
|
|
|
|
use AWS\CRT\HTTP\Request;
|
|
|
|
class FileHelper {
|
|
static $allowedVideoExtensions = ['mp4', 'mkv'];
|
|
static $allowedApkExtensions = ['apk'];
|
|
|
|
static function convertToStrJsValidation(array $allowedFileExtensions) {
|
|
// add leading '.' for every extension;
|
|
foreach($allowedFileExtensions as &$allowedFileExtension) { $allowedFileExtension = ".$allowedFileExtension"; }
|
|
unset($allowedFileExtension);
|
|
|
|
return implode(', ', $allowedFileExtensions);
|
|
}
|
|
|
|
static function convertToStrLaraValidation(array $allowedFileExtensions, $type = 'string') {
|
|
$validations = [
|
|
'mimes:' . implode(',', self::_convertFileExtensionToMimes($allowedFileExtensions)),
|
|
'extensions:' . implode(',', $allowedFileExtensions)
|
|
];
|
|
|
|
if($type == 'string') return implode('|', $validations);
|
|
else if($type == 'array') return $validations;
|
|
else throw new \Exception('Type not valid');
|
|
}
|
|
|
|
private static function _convertFileExtensionToMimes($allowedFileExtensions) {
|
|
$mimes = [];
|
|
foreach($allowedFileExtensions as $allowedFileExtension) {
|
|
if($allowedFileExtension == 'apk') $mimes[] = 'zip'; // mimes of apk == zip
|
|
else $mimes[] = $allowedFileExtension;
|
|
}
|
|
return $mimes;
|
|
}
|
|
}
|
|
?>
|