Skip to content

Commit 407cf8a

Browse files
committed
Merge pull request #10 from tsawler/Development
Development
2 parents 061a744 + b7f445d commit 407cf8a

File tree

4 files changed

+117
-21
lines changed

4 files changed

+117
-21
lines changed

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ following command:
4242

4343
`php artisan vendor:publish --tag=lfm_public`
4444

45-
1. If you want to customize the views, then publish the package's views:
45+
1. If you want to customize the look & feel, then publish the package's views:
4646

4747
`php artisan vendor:publish --tag=lfm_views`
4848

@@ -93,15 +93,7 @@ simply wrap the routes in a group, perhaps like this:
9393
{
9494
Route::get('/laravel-filemanager', 'Tsawler\Laravelfilemanager\controllers\LfmController@show');
9595
Route::post('/laravel-filemanager/upload', 'Tsawler\Laravelfilemanager\controllers\LfmController@upload');
96-
Route::get('/laravel-filemanager/data', 'Tsawler\Laravelfilemanager\controllers\LfmController@getData');
97-
Route::get('/laravel-filemanager/delete', 'Tsawler\Laravelfilemanager\controllers\LfmController@getDelete');
98-
Route::get('/laravel-filemanager/picsjson', 'Tsawler\Laravelfilemanager\controllers\LfmController@getImages');
99-
Route::get('/laravel-filemanager/newfolder', 'Tsawler\Laravelfilemanager\controllers\FolderController@getAddfolder');
100-
Route::get('/laravel-filemanager/deletefolder', 'Tsawler\Laravelfilemanager\controllers\FolderController@getDeletefolder');
101-
Route::get('/laravel-filemanager/crop', 'Tsawler\Laravelfilemanager\controllers\CropController@getCrop');
102-
Route::get('/laravel-filemanager/cropimage', 'Tsawler\Laravelfilemanager\controllers\CropController@getCropimage');
103-
Route::get('/laravel-filemanager/rename', 'Tsawler\Laravelfilemanager\controllers\RenameController@getRename');
104-
Route::get('/laravel-filemanager/scale', 'Tsawler\Laravelfilemanager\controllers\ScaleController@getScale');
96+
// list all lfm routes here...
10597
});
10698

10799
This approach ensures that only authenticated users have access to the Laravel-Filemanager. If you are
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php namespace Tsawler\Laravelfilemanager\controllers;
2+
3+
use App\Http\Controllers\Controller;
4+
use Illuminate\Support\Facades\Config;
5+
use Illuminate\Support\Facades\File;
6+
use Illuminate\Support\Facades\Input;
7+
use Illuminate\Support\Facades\Session;
8+
use Illuminate\Support\Str;
9+
use Intervention\Image\Facades\Image;
10+
11+
/**
12+
* Class LfmController
13+
* @package Tsawler\Laravelfilemanager\controllers
14+
*/
15+
class UploadController extends Controller {
16+
17+
/**
18+
* @var
19+
*/
20+
protected $file_location;
21+
22+
23+
/**
24+
* constructor
25+
*/
26+
function __construct()
27+
{
28+
if (Session::get('lfm_type') == "Images")
29+
$this->file_location = Config::get('lfm.images_dir');
30+
else
31+
$this->file_location = Config::get('lfm.files_dir');
32+
}
33+
34+
35+
/**
36+
* Upload an image and create thumbnail
37+
*
38+
* @param UploadRequest $request
39+
* @return string
40+
*/
41+
public function upload()
42+
{
43+
// sanity check
44+
if ( ! Input::hasFile('file_to_upload'))
45+
{
46+
// there ws no uploded file
47+
return "You must choose a file!";
48+
exit;
49+
}
50+
51+
52+
if (Session::get('lfm_type') == "Images")
53+
{
54+
$file = Input::file('file_to_upload');
55+
$working_dir = Input::get('working_dir');
56+
$destinationPath = base_path() . "/" . $this->file_location;
57+
58+
if (strlen($working_dir) > 1)
59+
{
60+
$destinationPath .= $working_dir . "/";
61+
}
62+
63+
$filename = $file->getClientOriginalName();
64+
$extension = $file->getClientOriginalExtension();
65+
66+
$new_filename = Str::slug(str_replace($extension, '', $filename)) . "." . $extension;
67+
68+
Input::file('file_to_upload')->move($destinationPath, $new_filename);
69+
70+
if (!File::exists($destinationPath . "thumbs"))
71+
{
72+
File::makeDirectory($destinationPath . "thumbs");
73+
}
74+
75+
$thumb_img = Image::make($destinationPath . $new_filename);
76+
$thumb_img->fit(200, 200)
77+
->save($destinationPath . "thumbs/" . $new_filename);
78+
unset($thumb_img);
79+
80+
return "OK";
81+
} else
82+
{
83+
$file = Input::file('file_to_upload');
84+
$working_dir = Input::get('working_dir');
85+
$destinationPath = base_path() . "/" . $this->file_location;
86+
87+
if (strlen($working_dir) > 1)
88+
{
89+
$destinationPath .= $working_dir . "/";
90+
}
91+
92+
$filename = $file->getClientOriginalName();
93+
$extension = $file->getClientOriginalExtension();
94+
95+
$new_filename = Str::slug(str_replace($extension, '', $filename)) . "." . $extension;
96+
97+
Input::file('file_to_upload')->move($destinationPath, $new_filename);
98+
99+
return "OK";
100+
}
101+
102+
}
103+
104+
}

src/routes.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66

77
// general routes
88
Route::get('/laravel-filemanager', 'Tsawler\Laravelfilemanager\controllers\LfmController@show');
9-
Route::post('/laravel-filemanager/upload', 'Tsawler\Laravelfilemanager\controllers\LfmController@upload');
10-
Route::get('/laravel-filemanager/data', 'Tsawler\Laravelfilemanager\controllers\LfmController@getData');
119
Route::get('/laravel-filemanager/delete', 'Tsawler\Laravelfilemanager\controllers\LfmController@getDelete');
1210

11+
// folder list
12+
Route::get('/laravel-filemanager/data', 'Tsawler\Laravelfilemanager\controllers\LfmController@getData');
13+
14+
// upload
15+
Route::any('/laravel-filemanager/upload', 'Tsawler\Laravelfilemanager\controllers\UploadController@upload');
16+
17+
// list images & files
1318
Route::get('/laravel-filemanager/jsonimages', 'Tsawler\Laravelfilemanager\controllers\LfmController@getImages');
1419
Route::get('/laravel-filemanager/jsonfiles', 'Tsawler\Laravelfilemanager\controllers\LfmController@getFiles');
1520

src/views/index.blade.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,6 @@ class="fa fa-list"></i> List</a>
137137
loadImages();
138138
});
139139
140-
function highlight(x) {
141-
$(".thumbnail-img").not('#' + x).removeClass('highlight');
142-
if ($("#" + x).hasClass('highlight')) {
143-
$("#" + x).removeClass('highlight');
144-
} else {
145-
$("#" + x).addClass('highlight');
146-
}
147-
}
148-
149140
$("#upload-btn").click(function () {
150141
var options = {
151142
beforeSubmit: showRequest,
@@ -159,6 +150,10 @@ function showRequest(formData, jqForm, options) {
159150
160151
function showResponse(responseText, statusText, xhr, $form) {
161152
$("#uploadModal").modal('hide');
153+
$("#upload-btn").html('Upload File...');
154+
if (responseText != "OK"){
155+
notify(responseText);
156+
}
162157
loadImages();
163158
}
164159

0 commit comments

Comments
 (0)