Skip to content

Commit 26cc276

Browse files
committed
new commit
2 parents 4660ae9 + 97c6378 commit 26cc276

File tree

14 files changed

+816
-564
lines changed

14 files changed

+816
-564
lines changed

README.md

Lines changed: 55 additions & 250 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# laravel-filemanager
1+
# Laravel Filemanager
2+
3+
[![Latest Stable Version](https://poser.pugx.org/unisharp/laravel-filemanager/v/stable)](https://packagist.org/packages/unisharp/laravel-filemanager) [![Total Downloads](https://poser.pugx.org/unisharp/laravel-filemanager/downloads)](https://packagist.org/packages/unisharp/laravel-filemanager) [![Latest Unstable Version](https://poser.pugx.org/unisharp/laravel-filemanager/v/unstable)](https://packagist.org/packages/unisharp/laravel-filemanager) [![License](https://poser.pugx.org/unisharp/laravel-filemanager/license)](https://packagist.org/packages/unisharp/laravel-filemanager)
24

35
A files and images management user interface with file uploading support. (Works well with CKEditor and TinyMCE)
46

@@ -7,279 +9,82 @@ PR is welcome!
79
## Overview
810

911
* The project was forked from [tsawler/laravel-filemanager](http://packalyst.com/packages/package/tsawler/laravel-filemanager)
10-
* Support public and private folders for multi users
11-
* Customizable views, routes and middlewares
12+
* Customizable routes and middlewares
1213
* Supported locales : en, fr, pt-BR, tr, zh-CN, zh-TW
14+
* Supports public and private folders for multi users
15+
* Supports multi-level folders
16+
* Supports using independently(see integration doc)
1317

18+
## Documents
1419

15-
## Requirements
16-
17-
* php >= 5.5
18-
* Laravel 5
19-
* requires [intervention/image](https://github.com/Intervention/image) (to make thumbs, crop and resize images).
20-
21-
## Notes
22-
23-
* For `laravel 5.2`, please set `'middlewares' => ['web', 'auth'],` in config/lfm.php
24-
* With laravel-filemanager >= 1.3.0, the new configs `valid_image_mimetypes` and `valid_file_mimetypes` restrict the MIME types of the uploading files.
25-
26-
## Installation
27-
28-
1. Install package
29-
30-
```bash
31-
composer require unisharp/laravel-filemanager
32-
```
33-
34-
1. Edit `config/app.php` :
35-
36-
Add service providers
37-
38-
```php
39-
Unisharp\Laravelfilemanager\LaravelFilemanagerServiceProvider::class,
40-
Intervention\Image\ImageServiceProvider::class,
41-
```
42-
43-
And add class aliases
44-
45-
```php
46-
'Image' => Intervention\Image\Facades\Image::class,
47-
```
48-
49-
1. Publish the package's config and assets :
50-
51-
```bash
52-
php artisan vendor:publish --tag=lfm_config
53-
php artisan vendor:publish --tag=lfm_public
54-
```
55-
56-
1. Ensure that the files & images directories (in `config/lfm.php`) are writable by your web server.
57-
58-
## WYSIWYG Editor Integration:
59-
### Option 1: CKEditor
20+
1. [Installation](https://github.com/UniSharp/laravel-filemanager/blob/master/doc/installation.md)
21+
1. [Intergration](https://github.com/UniSharp/laravel-filemanager/blob/master/doc/integration.md)
22+
1. [Config](https://github.com/UniSharp/laravel-filemanager/blob/master/doc/config.md)
23+
1. [Customization](https://github.com/UniSharp/laravel-filemanager/blob/master/doc/customization.md)
6024

61-
1. Install [laravel-ckeditor](https://github.com/UniSharp/laravel-ckeditor) package
25+
## Upgrade guide
26+
* `composer update unisharp/laravel-filemanager`
27+
* `php artisan vendor:publish --tag=lfm_view --force`
28+
* `php artisan vendor:publish --tag=lfm_config --force` (IMPORTANT: please backup your own `config/lfm.php` first)
6229

63-
1. Modify the views
64-
65-
Sample 1 - Replace by ID:
66-
```html
67-
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
68-
<textarea id="my-editor" name="content" class="form-control">{!! old('content', $content) !!}</textarea>
69-
<script>
70-
CKEDITOR.replace( 'my-editor', {
71-
filebrowserImageBrowseUrl: '/laravel-filemanager?type=Images',
72-
filebrowserImageUploadUrl: '/laravel-filemanager/upload?type=Images&_token={{csrf_token()}}',
73-
filebrowserBrowseUrl: '/laravel-filemanager?type=Files',
74-
filebrowserUploadUrl: '/laravel-filemanager/upload?type=Files&_token={{csrf_token()}}'
75-
});
76-
</script>
77-
```
78-
79-
Sample 2 - With JQuery Selector:
80-
81-
```html
82-
<script src="/vendor/unisharp/laravel-ckeditor/ckeditor.js"></script>
83-
<script src="/vendor/unisharp/laravel-ckeditor/adapters/jquery.js"></script>
84-
<textarea name="content" class="form-control my-editor">{!! old('content', $content) !!}</textarea>
85-
<script>
86-
$('textarea.my-editor').ckeditor({
87-
filebrowserImageBrowseUrl: '/laravel-filemanager?type=Images',
88-
filebrowserImageUploadUrl: '/laravel-filemanager/upload?type=Images&_token={{csrf_token()}}',
89-
filebrowserBrowseUrl: '/laravel-filemanager?type=Files',
90-
filebrowserUploadUrl: '/laravel-filemanager/upload?type=Files&_token={{csrf_token()}}'
91-
});
92-
</script>
93-
```
94-
95-
### Option 2: TinyMCE4
96-
97-
```html
98-
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
99-
<textarea name="content" class="form-control my-editor">{!! old('content', $content) !!}</textarea>
100-
<script>
101-
var editor_config = {
102-
path_absolute : "/",
103-
selector: "textarea",
104-
plugins: [
105-
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
106-
"searchreplace wordcount visualblocks visualchars code fullscreen",
107-
"insertdatetime media nonbreaking save table contextmenu directionality",
108-
"emoticons template paste textcolor colorpicker textpattern"
109-
],
110-
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media",
111-
relative_urls: false,
112-
file_browser_callback : function(field_name, url, type, win) {
113-
var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
114-
var y = window.innerHeight|| document.documentElement.clientHeight|| document.getElementsByTagName('body')[0].clientHeight;
115-
116-
var cmsURL = editor_config.path_absolute + 'laravel-filemanager?field_name=' + field_name;
117-
if (type == 'image') {
118-
cmsURL = cmsURL + "&type=Images";
119-
} else {
120-
cmsURL = cmsURL + "&type=Files";
121-
}
122-
123-
tinyMCE.activeEditor.windowManager.open({
124-
file : cmsURL,
125-
title : 'Filemanager',
126-
width : x * 0.8,
127-
height : y * 0.8,
128-
resizable : "yes",
129-
close_previous : "no"
130-
});
131-
}
132-
};
133-
134-
tinymce.init(editor_config);
135-
</script>
136-
```
137-
138-
##Independent use
139-
140-
If you are going to use filemanager independently,meaning set the value of an input to selected photo/file url,follow this structure:
141-
142-
1. create a popup window or modal(whatever you like):
143-
144-
```html
145-
<a href="/laravel-filemanager" id="feature-img-container"><img src="no_photo.jpg"></a>
146-
<input name="thumbnail" type="hidden" id="thumbnail">
147-
```
148-
149-
```javascript
150-
$('#feature-img-container').on('click', function(e)
151-
{
30+
## Screenshots
31+
* Independent usage example :
15232

153-
window.open(this.href, 'Filemanager', 'width=900,height=600');
33+
![Independent usage example](http://unisharp.github.io/images/lfm01.png)
15434

155-
return false;
156-
});
157-
```
35+
* List view :
15836

159-
2. define a function named `SetUrl`:
37+
![FileManager screenshot 1](http://unisharp.com/img/filemanager1.png)
16038

161-
```javascript
162-
function SetUrl(url){
39+
* Grid view :
16340

164-
//set the value of the desired input to image url,often this is a hidden input
165-
$('#thumbnail').val(url);
166-
167-
//set or change the feature image src,recall wordpress feature image
168-
$('#feature-img-container').find('img').attr('src',url);
169-
}
170-
```
41+
![FileManager screenshot 2](http://unisharp.com/img/filemanager2.png)
17142

43+
## Events
17244

173-
## Config
174-
175-
In `config/lfm.php` :
45+
To use events you can add a listener to listen to the events
17646

47+
Snippet for `EventServiceProvider`
17748
```php
178-
'rename_file' => true,
179-
// true : files will be renamed as uniqid
180-
// false : files will remain original names
181-
182-
'use_package_routes' => true,
183-
// set this to false to customize route for file manager
184-
185-
'middlewares' => ['auth'],
186-
// determine middlewares that apply to all file manager routes
187-
// NOTE: for laravel 5.2, please use ['web', 'auth']
188-
189-
'allow_multi_user' => true,
190-
// true : user can upload files to shared folder and their own folder
191-
// false : all files are put together in shared folder
192-
193-
'user_field' => 'id',
194-
// determine which column of users table will be used as user's folder name
195-
196-
'shared_folder_name' => 'shares',
197-
// the name of shared folder
198-
199-
'thumb_folder_name' => 'thumbs',
200-
// the name of thumb folder
201-
202-
'images_dir' => 'public/photos/',
203-
'images_url' => '/photos/',
204-
// path and url of images
205-
206-
'files_dir' => 'public/files/',
207-
'files_url' => '/files/',
208-
// path and url of files
209-
210-
211-
// valid image mimetypes
212-
'valid_image_mimetypes' => [
213-
'image/jpeg',
214-
'image/pjpeg',
215-
'image/png',
216-
'image/gif'
217-
],
218-
219-
220-
// valid file mimetypes (only when '/laravel-filemanager?type=Files')
221-
'valid_file_mimetypes' => [
222-
'image/jpeg',
223-
'image/pjpeg',
224-
'image/png',
225-
'image/gif',
226-
'application/pdf',
227-
'text/plain'
228-
],
49+
protected $listen = [
50+
ImageWasUploaded::class => [
51+
UploadListener::class,
52+
],
53+
];
22954
```
23055

231-
## Customization
232-
233-
1. If the route is changed, make sure urls below is correspond to your route :
234-
235-
CKEditor
236-
```javascript
237-
<script>
238-
CKEDITOR.replace( 'editor', {
239-
filebrowserImageBrowseUrl: '/your-custom-route?type=Images',
240-
filebrowserBrowseUrl: '/your-custom-route?type=Files',
241-
});
242-
</script>
243-
```
244-
245-
And be sure to include the `?type=Images` or `?type=Files` parameter.
246-
247-
TinyMCE
248-
```javascript
249-
...
250-
var cmsURL = editor_config.path_absolute + 'your-custom-route?field_name='+field_name+'&lang='+ tinymce.settings.language;
251-
if (type == 'image') {
252-
cmsURL = cmsURL + "&type=Images";
253-
} else {
254-
cmsURL = cmsURL + "&type=Files";
56+
The `UploadListener` will look like:
57+
```php
58+
class UploadListener
59+
{
60+
public function handle($event)
61+
{
62+
$method = 'on'.class_basename($event);
63+
if (method_exists($this, $method)) {
64+
call_user_func([$this, $method], $event);
25565
}
256-
...
257-
```
258-
259-
1. To customize the views :
260-
261-
on Linux :
262-
263-
```bash
264-
cp -rf vendor/unisharp/laravel-filemanager/src/views/* resources/views/vendor/laravel-filemanager/
265-
```
266-
267-
on MAC :
66+
}
26867

269-
```bash
270-
cp -rf vendor/unisharp/laravel-filemanager/src/views/ resources/views/vendor/laravel-filemanager/
271-
```
68+
public function onImageWasUploaded(ImageWasUploaded $event)
69+
{
70+
$path = $event->path();
71+
//your code, for example resizing and cropping
72+
}
73+
}
74+
```
27275

273-
## Screenshots
274-
![FileManager screenshot 1](http://unisharp.com/img/filemanager1.png)
275-
![FileManager screenshot 2](http://unisharp.com/img/filemanager2.png)
76+
List of events:
77+
* Unisharp\Laravelfilemanager\Events\ImageWasUploaded
27678

27779
## Credits
27880
* All contibutors from GitHub. (issues / PR)
27981
* Special thanks to
28082
* [@taswler](https://github.com/tsawler) the original author.
83+
* [@olivervogel](https://github.com/olivervogel) for the awesome [image library](https://github.com/Intervention/image)
28184
* [@welcoMattic](https://github.com/welcoMattic) providing fr translations and lots of bugfixes.
28285
* [@fraterblack](https://github.com/fraterblack) TinyMCE 4 support and pt-BR translations.
28386
* [@1dot44mb](https://github.com/1dot44mb) tr translations.
284-
* [@olivervogel](https://github.com/olivervogel) for the awesome [image library](https://github.com/Intervention/image)
285-
* [All @UniSharp members](https://github.com/UniSharp)
87+
* [@Nikita240](https://github.com/Nikita240) fixing controller extending errors.
88+
* [@amin101](https://github.com/amin101) guide for independent use and fixes for url/directory error on Windows
89+
* [@nasirkhan](https://github.com/nasirkhan) bug fixes and alphanumeric filename check
90+
* All [@UniSharp](https://github.com/UniSharp) members

0 commit comments

Comments
 (0)