Filemanager
Filemanager package for Laravel 5.5, (*1)
Installation
To install, run the following in your project directory:, (*2)
``` bash
$ composer require div-art/filemanager, (*3)
Then in `config/app.php` add the following to the `providers` array:
\Divart\Filemanager\FilemanagerServiceProvider::class,
'Tymon\JWTAuth\Providers\JWTAuthServiceProvider',, (*4)
Also in config/app.php, add the Facade class to the aliases array:
'Filemanager' => \Divart\Filemanager\Facades\Filemanager::class,
'JWTAuth' => 'Tymon\JWTAuth\Facades\JWTAuth', (*5)
## Configuration
To publish Filemanager's configuration file, run the following `vendor:publish` command:
php artisan vendor:publish --provider="Divart\Filemanager\FilemanagerServiceProvider"
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider", (*6)
Now for token encryption, I need to generate a secret key by running following line of code :
php artisan jwt:secret, (*7)
Now I will create middleware to check if the token is valid or not and also You can handle the exception if the token is expired.
php artisan make:middleware VerifyJWTToken, (*8)
Using this middleware, you can filter the request and validate the JWT token.
Now open your VerifyJWTToken middleware and put below line of code.
app/Http/Middleware/VerifyJWTToken.php
pop-uptext
<?php, (*9)
namespace App\Http\Middleware;, (*10)
use Closure;
use JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;, (*11)
class VerifyJWTToken
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
try{
$user = JWTAuth::toUser($request->input('token'));
}catch (JWTException $e) {
if($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException) {
return response()->json(['token_expired'], $e->getStatusCode());
}else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) {
return response()->json(['token_invalid'], $e->getStatusCode());
}else{
return response()->json(['error'=>'Token is required']);
}
}
return $next($request);
}
}, (*12)
The try block in handle method check if requested token is verified by JWTAuth or not if it is not verified then exception will be handled in catch block with their status.
Now register this middleware in your kernal to run during every HTTP request to your application.
app/Http/Kernel.php
protected $routeMiddleware = [
...
'jwt.auth' => \App\Http\Middleware\VerifyJWTToken::class,
];, (*13)
## Usage
Add from ENV file:
#FILEMANAGER_LOCATION - File manager location
FILEMANAGER_LOCATION=myfilemanager, (*14)
Since the file manager only works with authorized users, you need to make a connection to the database, and create a plaque for users with minimal fields email, password
If you do not have it, you can do it using the command:
php artisan make:auth, (*15)
Available routes
To work with the file manager you need to login
by POST method, send an email address and password to this route to authorize and receive a token
http.youdomain.com/auth/login, (*16)
File Manager Routes
All file manager paths have a prefix 'filemanager'
example:
method GET
{http.youdomain.com}/filemanager, (*17)
this method open filemanager and scan him
method GET
{http.youdomain.com}/filemanager/folder/{path to folder?}, (*18)
this route open this selected folder
method POST
{http.youdomain.com}/filemanager/folder/create/{path to folder?}, (*19)
this method create new folder in this directory
Need to send data: 'name' - is name folder
method POST
{http.youdomain.com}/filemanager/file/create/{path to file?}, (*20)
this method create file
Need to send: 'name' and 'data' where value name is name file and your expansion, 'data' is content file
method POST
{http.youdomain.com}/filemanager/file/upload/{path to file?}, (*21)
this method upload file
method PUT
{http.youdomain.com}/filemanager/folder/update/{path to folder}, (*22)
this method update(rename folder) selected folder in this directory
Need to send data: 'name', 'newname' where 'name' is name selected folder and 'newname' that new name folder
method PUT
{http.youdomain.com}/filemanager/file/update/{path to file?}, (*23)
Need to send: 'name' and 'data' where value name is name file and your expansion, 'data' is content file
method DELETE
{http.youdomain.com}/filemanager/folder/delete/{path to folder}, (*24)
this method delete selected folder in this directory
Need to send data: 'name', where value is name selected folder
method DELETE
{http.youdomain.com}/filemanager/file/delete/{path to file?}, (*25)
Need to send: 'name' and the file is deleted
method GET
{http.youdomain.com}/filemanager/file/{filename}/folder/{path to file?}, (*26)
this method return file data
method POST
{http.youdomain.com}/filemanager/folder/changelocation/{path to folder}, (*27)
this method change location folder and the attachments in it are files
Need to send data: 'from', 'to'. 'from' - address from which of the derivatives, 'to' - where to move
method POST
{http.youdomain.com}/filemanager/file/changelocation/{path to folder?}, (*28)
this method change location file
Need to send data: 'from', 'to'. 'from' - address from which of the derivatives, 'to' - where to move
method POST
{http.youdomain.com}/filemanager/folder/{folder?}
```, (*29)
this method accepts data for sorting items into a file manager, (*30)
Need to send data: 'value' and 'type'. 'value' may be important 'size' or 'time', 'type' may be important 'SORT_ASC' or SORT_DESC.
Defaul is 'value' = 'time', 'type' = SORT_ASC, (*31)
License
The MIT License (MIT). Please see License File for more information."# Filemanager"
"# Filemanager", (*32)