PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.45
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.45
2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 1.45 All 41 releases
fluent-boards / app / Services / UploadService.php

UploadService.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.45, at app/Services/UploadService.php

56 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\App\Services;
4
5
6 use FluentBoards\App\Services\Libs\FileSystem;
7 use FluentBoards\Framework\Support\Arr;
8
9 class UploadService
10 {
11
12 /**
13 * @throws \Exception
14 */
15 public static function handleFileUpload($file, $boardId, $taskId = null)
16 {
17 $uploadInfo = FileSystem::setSubDir('board_'.$boardId)->put($file);
18
19 if (!empty($uploadInfo) && is_array($uploadInfo)) {
20 return $uploadInfo;
21 }
22
23 return new \WP_Error('file_upload_error', __('File upload failed', 'fluent-boards'));
24 }
25
26 public function validateFile($file)
27 {
28 if (!$file) {
29 throw new \Exception('File is empty.');
30 }
31 if (!$this->isFileTypeSupported($file)) {
32 throw new \Exception('File type not supported');
33 }
34 if ($file['size'] > $this->getFileUploadLimit()) {
35 throw new \Exception('File size is too large');
36 }
37 }
38
39 public function getFileUploadLimit() {
40 // Logic for calculating file upload limit as in your original code
41 return min(
42 wp_convert_hr_to_bytes(ini_get('upload_max_filesize')),
43 wp_convert_hr_to_bytes(ini_get('post_max_size')),
44 wp_max_upload_size()
45 );
46 }
47
48 public function isFileTypeSupported($file)
49 {
50 // Define supported file types that are generally allowed by user
51 $allowedMimeTypes = get_allowed_mime_types();
52 // Check if the file type is supported
53 return in_array(strtolower($file['type']), $allowedMimeTypes);
54 }
55
56 }