|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Crocodicstudio\Crudbooster\Modules\FileManagerModule; |
|
4
|
|
|
|
|
5
|
|
|
use Crocodicstudio\Crudbooster\controllers\CBController; |
|
6
|
|
|
use Crocodicstudio\Crudbooster\Modules\ModuleGenerator\ControllerGenerator\FieldDetector; |
|
7
|
|
|
use Illuminate\Support\Facades\Storage; |
|
8
|
|
|
use Illuminate\Support\Facades\Request; |
|
9
|
|
|
|
|
10
|
|
|
class AdminFileManagerController extends CBController |
|
11
|
|
|
{ |
|
12
|
|
|
public function cbInit() |
|
13
|
|
|
{ |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function getIndex() |
|
17
|
|
|
{ |
|
18
|
|
|
$path = request('path') ? base64_decode(request('path')) : ''; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
if (strpos($path, '..') || $path == '.' || strpos($path, '/.')) { |
|
21
|
|
|
return redirect()->route('AdminFileManagerControllerGetIndex'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
$currentPath = $path ?: 'uploads'; |
|
25
|
|
|
$currentPath = trim($currentPath, '/'); |
|
26
|
|
|
|
|
27
|
|
|
$directories = Storage::directories($currentPath); |
|
28
|
|
|
$files = Storage::files($currentPath); |
|
29
|
|
|
|
|
30
|
|
|
return view('CbFileManager::index', ['files' => $files, 'directories' => $directories, 'currentPath' => $currentPath]); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function postCreateDirectory() |
|
34
|
|
|
{ |
|
35
|
|
|
$path = (base64_decode(request('path'))) ?: 'uploads'; |
|
|
|
|
|
|
36
|
|
|
$name = str_slug(request('name'), '_'); |
|
|
|
|
|
|
37
|
|
|
Storage::makeDirectory($path.'/'.$name); |
|
38
|
|
|
|
|
39
|
|
|
backWithMsg('The directory has been created!'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function postUpload() |
|
43
|
|
|
{ |
|
44
|
|
|
$path = request('path') ? base64_decode(request('path')) : 'uploads'; |
|
|
|
|
|
|
45
|
|
|
$file = Request::file('userfile'); |
|
46
|
|
|
if (! $file) { |
|
47
|
|
|
return null; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$fileName = $file->getClientOriginalName(); |
|
51
|
|
|
|
|
52
|
|
|
if (! FieldDetector::isUploadField($file->getClientOriginalExtension())) { |
|
53
|
|
|
backWithMsg('The file '.$fileName.' type is not allowed!', 'warning'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
Storage::putFileAs($path, $file, $fileName); |
|
57
|
|
|
|
|
58
|
|
|
backWithMsg('The file '.$fileName.' has been uploaded!'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getDeleteDirectory($dir) |
|
62
|
|
|
{ |
|
63
|
|
|
$dir = base64_decode($dir); |
|
64
|
|
|
Storage::deleteDirectory($dir); |
|
65
|
|
|
|
|
66
|
|
|
backWithMsg('The directory has been deleted!'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getDeleteFile($file) |
|
70
|
|
|
{ |
|
71
|
|
|
$file = base64_decode($file); |
|
72
|
|
|
if(Storage::delete($file)) |
|
73
|
|
|
backWithMsg('The file has been deleted!'); |
|
74
|
|
|
|
|
75
|
|
|
backWithMsg('The file did not deleted!', 'warning'); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|