Skip to content

Commit

Permalink
add config for filename check, update documents, fix issue #50
Browse files Browse the repository at this point in the history
  • Loading branch information
streamtw committed Mar 26, 2016
1 parent 42235c5 commit b6cdd52
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ PR is welcome!
1. [Config](https://github.com/UniSharp/laravel-filemanager/blob/master/doc/config.md)
1. [Customization](https://github.com/UniSharp/laravel-filemanager/blob/master/doc/customization.md)

## Upgrade guide
* `composer update unisharp/laravel-filemanager`
* `php artisan vendor:publish --tag=lfm_view --force`
* `php artisan vendor:publish --tag=lfm_config --force`(remember to keep your previous settings in `config/lfm.php`)

## Screenshots
* Independent usage example :
![Independent usage example](http://unisharp.github.io/images/lfm01.png)
* List view :
![FileManager screenshot 1](http://unisharp.com/img/filemanager1.png)
* Grid view :
![FileManager screenshot 2](http://unisharp.com/img/filemanager2.png)

## Credits
Expand Down
3 changes: 3 additions & 0 deletions doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ In `config/lfm.php` :
// true : files will be renamed as uniqid
// false : files will remain original names

// true : filter filename characters which are not English or numbers, and replace them with '_'
'check_filename' => true,

'use_package_routes' => true,
// set this to false to customize route for file manager

Expand Down
2 changes: 1 addition & 1 deletion doc/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feel free to customize the routes and views if your need.

### Routes

1. Copy the routes in src/routes.php
1. Copy the routes in /vendor/unisharp/laravel-filemanager/src/routes.php

1. Make sure urls below is correspond to your route :

Expand Down
3 changes: 3 additions & 0 deletions src/config/lfm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// If true, the uploaded file will be renamed to uniqid() + file extension.
'rename_file' => true,

// If rename_file set to false and this set to true, then filter filename characters which are not English or numbers.
'check_filename' => true,

'use_package_routes' => true,

// For laravel 5.2, please set to ['web', 'auth']
Expand Down
10 changes: 8 additions & 2 deletions src/controllers/LfmController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct()
public function show()
{
$working_dir = '/';
$working_dir .= (Config::get('lfm.allow_multi_user')) ? \Auth::user()->user_field : Config::get('lfm.shared_folder_name');
$working_dir .= (Config::get('lfm.allow_multi_user')) ? $this->getUserSlug() : Config::get('lfm.shared_folder_name');

return view('laravel-filemanager::index')
->with('working_dir', $working_dir)
Expand Down Expand Up @@ -81,7 +81,7 @@ private function formatLocation($location, $type = null, $get_thumb = false)
if ($type === 'share') {
return $location . Config::get('lfm.shared_folder_name');
} elseif ($type === 'user') {
return $location . \Auth::user()->user_field;
return $location . $this->getUserSlug();
}

$working_dir = Input::get('working_dir');
Expand Down Expand Up @@ -115,6 +115,12 @@ private function formatLocation($location, $type = null, $get_thumb = false)
****************************/


public function getUserSlug()
{
return empty(auth()->user()) ? '' : \Auth::user()->user_field;
}


public function getPath($type = null, $get_thumb = false)
{
$path = base_path() . '/' . $this->file_location;
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function getNewName($file)

if (Config::get('lfm.rename_file') === true) {
$new_filename = uniqid();
} else {
} elseif (Config::get('lfm.check_filename') === true) {
$new_filename = preg_replace('/[^A-Za-z0-9\-\']/', '_', $file->getClientOriginalName());
}

Expand Down

0 comments on commit b6cdd52

Please sign in to comment.