1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2019 Amin Yazdanpanah<http://www.aminyazdanpanah.com>. |
5
|
|
|
* |
6
|
|
|
* Licensed under the MIT License; |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* https://opensource.org/licenses/MIT |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace AYazdanpanah\SaveUploadedFiles; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
class Helper |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @param $type |
26
|
|
|
* @param $filename |
27
|
|
|
* @return bool |
28
|
|
|
*/ |
29
|
|
|
public static function isType($type, $filename): bool |
30
|
|
|
{ |
31
|
|
|
return boolval(strstr(mime_content_type($filename), $type)); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param int $length |
36
|
|
|
* @return bool|string |
37
|
|
|
*/ |
38
|
|
|
public static function str_random($length = 10) |
39
|
|
|
{ |
40
|
|
|
return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public static function videoTypes(): array |
47
|
|
|
{ |
48
|
|
|
return [ |
49
|
|
|
'webm', 'mkv', 'flv', 'vob', 'ogv', 'ogg', 'drc', 'gif', 'gifv', 'avi', |
50
|
|
|
'MTS', 'M2TS', 'mov', 'qt', 'yuv', 'rm', 'rmvb', 'asf', 'amv', 'mp4', |
51
|
|
|
'm4p ', 'm4v', 'mpg', 'mp2', 'mpeg', 'mpe', 'mpg', 'mpeg', 'm2v', '3gp', |
52
|
|
|
'3g2', 'mxf', 'roq', 'nsv', 'flv', 'f4v', 'f4p', 'f4a', 'f4b', |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
} |