|
1
|
|
|
<?php |
|
2
|
|
|
use LaravelRealtimeChat\Repositories\Team\TeamRepository; |
|
3
|
|
|
use LaravelRealtimeChat\Repositories\Task\TaskRepository; |
|
4
|
|
|
class FileUploadController extends AuthController { |
|
5
|
|
|
private $taskRepository; |
|
6
|
|
|
|
|
7
|
|
|
public function __construct(TeamRepository $teamRepository, TaskRepository $taskRepository) { |
|
8
|
|
|
$this->teamRepository = $teamRepository; |
|
|
|
|
|
|
9
|
|
|
$this->taskRepository = $taskRepository; |
|
10
|
|
|
} |
|
11
|
|
|
public function uploadFiles($name) { |
|
12
|
|
|
|
|
13
|
|
|
switch ($name) { |
|
14
|
|
|
case "chat":$folderName = "userUploads"; |
|
15
|
|
|
$this->validateAndUpload($folderName,false);//set true for db operations,else false |
|
16
|
|
|
break; |
|
17
|
|
|
|
|
18
|
|
|
case "task":$folderName = "userTaskFiles"; |
|
19
|
|
|
$this->validateAndUpload($folderName,true); |
|
20
|
|
|
break; |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
function validateAndUpload($folderName,$dbSave) { |
|
|
|
|
|
|
26
|
|
|
$successStatus; |
|
|
|
|
|
|
27
|
|
|
$fileErr; |
|
|
|
|
|
|
28
|
|
|
// Build the input for our validation |
|
29
|
|
|
$input = Input::all(); |
|
|
|
|
|
|
30
|
|
|
// Within the ruleset, make sure we let the validator know that this |
|
31
|
|
|
// file should be an image |
|
32
|
|
|
$rules = array( |
|
33
|
|
|
'file' => 'max:100000000', |
|
34
|
|
|
); |
|
35
|
|
|
$validation = Validator::make($input, $rules); |
|
36
|
|
|
|
|
37
|
|
|
if ($validation->fails()) { |
|
38
|
|
|
return Response::make($validation->errors->first(), 400); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$file = Input::file('file'); |
|
42
|
|
|
foreach ($file as $files) { |
|
43
|
|
|
|
|
44
|
|
|
$upload_success = $files->move('fusionmate/public/plugins/' . $folderName . '', $files->getClientOriginalName()); |
|
45
|
|
|
|
|
46
|
|
|
$imgPath = $files->getClientOriginalName(); |
|
47
|
|
|
|
|
48
|
|
|
if ($upload_success) { |
|
49
|
|
|
if($dbSave){ |
|
50
|
|
|
$this->taskRepository->saveTaskFiles($imgPath); |
|
51
|
|
|
} |
|
52
|
|
|
$fileErr = false; |
|
53
|
|
|
} |
|
54
|
|
|
else { |
|
55
|
|
|
$fileErr = true; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
if (!$fileErr) { |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$successStatus = Response::json('success', 200); |
|
61
|
|
|
} |
|
62
|
|
|
else { |
|
63
|
|
|
$successStatus = Response::json('error', 400); |
|
64
|
|
|
} |
|
65
|
|
|
return $successStatus; |
|
66
|
|
|
} |
|
67
|
|
|
} |