Skip to content

Commit 76c3643

Browse files
committed
Merge pull request #11 from tsawler/Development
Development
2 parents 407cf8a + e4d09e6 commit 76c3643

File tree

10 files changed

+263
-196
lines changed

10 files changed

+263
-196
lines changed

public/css/lfm.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ html, body {
44

55
.img-row {
66
overflow: visible;
7+
margin-bottom: 10px;
78
}
89

910
.container {
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
9+
/**
10+
* Class CropController
11+
* @package Tsawler\Laravelfilemanager\controllers
12+
*/
13+
class DeleteController extends Controller {
14+
15+
/**
16+
* @var
17+
*/
18+
protected $file_location;
19+
20+
21+
/**
22+
* constructor
23+
*/
24+
function __construct()
25+
{
26+
if (Session::get('lfm_type') == "Images")
27+
$this->file_location = Config::get('lfm.images_dir');
28+
else
29+
$this->file_location = Config::get('lfm.files_dir');
30+
}
31+
32+
33+
/**
34+
* Delete image and associated thumbnail
35+
*
36+
* @return mixed
37+
*/
38+
public function getDelete()
39+
{
40+
$to_delete = Input::get('items');
41+
$base = Input::get("base");
42+
43+
if ($base != "/")
44+
{
45+
if (File::isDirectory(base_path() . "/" . $this->file_location . $to_delete))
46+
{
47+
File::delete(base_path() . "/" . $this->file_location . $base . "/" . $to_delete);
48+
49+
return "OK";
50+
} else
51+
{
52+
if (File::exists(base_path() . "/" . $this->file_location . $base . "/" . $to_delete))
53+
{
54+
File::delete(base_path() . "/" . $this->file_location . $base . "/" . $to_delete);
55+
56+
if (Session::get('lfm_type') == "Images'")
57+
File::delete(base_path() . "/" . $this->file_location . $base . "/" . "thumbs/" . $to_delete);
58+
59+
return "OK";
60+
} else {
61+
return base_path() . "/" . $this->file_location . $base . "/" . $to_delete
62+
. " not found!";
63+
}
64+
}
65+
} else
66+
{
67+
$file_name = base_path() . "/" . $this->file_location . $to_delete;
68+
if (File::isDirectory($file_name))
69+
{
70+
// make sure the directory is empty
71+
if (sizeof(File::files($file_name)) == 0)
72+
{
73+
File::deleteDirectory($file_name);
74+
75+
return "OK";
76+
} else
77+
{
78+
return "You cannot delete this folder because it is not empty!";
79+
}
80+
} else
81+
{
82+
if (File::exists($file_name))
83+
{
84+
File::delete($file_name);
85+
if (Session::get('lfm_type') == "Images'")
86+
File::delete(base_path() . "/" . $this->file_location . "thumbs/" . $to_delete);
87+
88+
return "OK";
89+
}
90+
}
91+
}
92+
}
93+
94+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php namespace Tsawler\Laravelfilemanager\controllers;
2+
3+
use App\Http\Controllers\Controller;
4+
use Illuminate\Support\Facades\Config;
5+
use Illuminate\Support\Facades\Input;
6+
use Illuminate\Support\Facades\Response;
7+
use Illuminate\Support\Facades\Session;
8+
9+
/**
10+
* Class LfmController
11+
* @package Tsawler\Laravelfilemanager\controllers
12+
*/
13+
class DownloadController extends Controller {
14+
15+
/**
16+
* @var
17+
*/
18+
protected $file_location;
19+
20+
21+
/**
22+
* constructor
23+
*/
24+
function __construct()
25+
{
26+
if (Session::get('lfm_type') == "Images")
27+
$this->file_location = Config::get('lfm.images_dir');
28+
else
29+
$this->file_location = Config::get('lfm.files_dir');
30+
}
31+
32+
33+
/**
34+
* Download a file
35+
*
36+
* @return mixed
37+
*/
38+
public function getDownload()
39+
{
40+
$file_to_download = Input::get('file');
41+
$dir = Input::get('dir');
42+
return Response::download(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_download);
43+
}
44+
}

src/controllers/FolderController.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Facades\Redirect;
88
use Illuminate\Support\Str;
99
use Illuminate\Support\Facades\Session;
10+
use Illuminate\Support\Facades\View;
1011

1112
/**
1213
* Class FolderController
@@ -25,6 +26,29 @@ function __construct()
2526
}
2627

2728

29+
/**
30+
* Get list of folders as json to populate treeview
31+
*
32+
* @return mixed
33+
*/
34+
public function getFolders()
35+
{
36+
$directories = File::directories(base_path($this->file_location));
37+
$final_array = [];
38+
39+
foreach ($directories as $directory)
40+
{
41+
if (basename($directory) != "thumbs")
42+
{
43+
$final_array[] = basename($directory);
44+
}
45+
}
46+
47+
return View::make("laravel-filemanager::tree")
48+
->with('dirs', $final_array);
49+
}
50+
51+
2852
/**
2953
* Add a new folder
3054
*
@@ -61,4 +85,5 @@ public function getDeletefolder()
6185

6286
return Redirect::to('/laravel-filemanager?' . Config::get('lfm.params'));
6387
}
64-
}
88+
89+
}

src/controllers/LfmController.php

Lines changed: 6 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
use Illuminate\Support\Facades\Input;
77
use Illuminate\Support\Facades\Session;
88
use Illuminate\Support\Facades\View;
9-
use Illuminate\Support\Str;
109
use Intervention\Image\Facades\Image;
11-
use Illuminate\Support\Facades\Log;
1210

1311
/**
1412
* Class LfmController
@@ -43,14 +41,14 @@ public function __construct()
4341
*/
4442
public function show()
4543
{
46-
if (Input::get('type') == "Images")
47-
{
48-
Session::put('lfm_type', 'Images');
49-
$this->file_location = Config::get('lfm.images_dir');
50-
} else
44+
if ((Input::has('type')) && (Input::get('type') == "Files"))
5145
{
5246
Session::put('lfm_type', 'Files');
5347
$this->file_location = Config::get('lfm.files_dir');
48+
} else
49+
{
50+
Session::put('lfm_type', 'Images');
51+
$this->file_location = Config::get('lfm.images_dir');
5452
}
5553

5654
if (Input::has('base'))
@@ -69,154 +67,13 @@ public function show()
6967
}
7068

7169

72-
/**
73-
* Upload an image and create thumbnail
74-
*
75-
* @param UploadRequest $request
76-
* @return string
77-
*/
78-
public function upload()
79-
{
80-
if (Session::get('type') == "Image")
81-
{
82-
$file = Input::file('file_to_upload');
83-
$working_dir = Input::get('working_dir');
84-
$destinationPath = base_path() . "/" . $this->file_location;
85-
86-
if (strlen($working_dir) > 1)
87-
{
88-
$destinationPath .= $working_dir . "/";
89-
}
90-
91-
$filename = $file->getClientOriginalName();
92-
$extension = $file->getClientOriginalExtension();
93-
94-
$new_filename = Str::slug(str_replace($extension, '', $filename)) . "." . $extension;
95-
96-
Input::file('file_to_upload')->move($destinationPath, $new_filename);
97-
98-
if (!File::exists($destinationPath . "thumbs"))
99-
{
100-
File::makeDirectory($destinationPath . "thumbs");
101-
}
102-
103-
$thumb_img = Image::make($destinationPath . $new_filename);
104-
$thumb_img->fit(200, 200)
105-
->save($destinationPath . "thumbs/" . $new_filename);
106-
unset($thumb_img);
107-
108-
return "OK";
109-
} else
110-
{
111-
$file = Input::file('file_to_upload');
112-
$working_dir = Input::get('working_dir');
113-
$destinationPath = base_path() . "/" . $this->file_location;
114-
115-
if (strlen($working_dir) > 1)
116-
{
117-
$destinationPath .= $working_dir . "/";
118-
}
119-
120-
$filename = $file->getClientOriginalName();
121-
$extension = $file->getClientOriginalExtension();
122-
123-
$new_filename = Str::slug(str_replace($extension, '', $filename)) . "." . $extension;
124-
125-
Input::file('file_to_upload')->move($destinationPath, $new_filename);
126-
127-
return "OK";
128-
}
129-
130-
}
131-
132-
133-
/**
134-
* Get data as json to populate treeview
135-
*
136-
* @return mixed
137-
*/
138-
public function getData()
139-
{
140-
if (Session::get('lfm_type') == 'Images')
141-
$directories = File::directories(base_path(Config::get('lfm.images_dir')));
142-
else
143-
$directories = File::directories(base_path(Config::get('lfm.files_dir')));
144-
$final_array = [];
145-
foreach ($directories as $directory)
146-
{
147-
if (basename($directory) != "thumbs")
148-
{
149-
$final_array[] = basename($directory);
150-
}
151-
}
152-
153-
return View::make("laravel-filemanager::tree")
154-
->with('dirs', $final_array);
155-
}
156-
157-
158-
/**
159-
* Delete image and associated thumbnail
160-
*
161-
* @return mixed
162-
*/
163-
public function getDelete()
164-
{
165-
$to_delete = Input::get('items');
166-
$base = Input::get("base");
167-
168-
if ($base != "/")
169-
{
170-
if (File::isDirectory(base_path() . "/" . Config::get('lfm.images_dir') . $to_delete))
171-
{
172-
File::delete(base_path() . "/" . Config::get('lfm.images_dir') . $base . "/" . $to_delete);
173-
174-
return "OK";
175-
} else
176-
{
177-
if (File::exists(base_path() . "/" . Config::get('lfm.images_dir') . $base . "/" . $to_delete))
178-
{
179-
File::delete(base_path() . "/" . Config::get('lfm.images_dir') . $base . "/" . $to_delete);
180-
File::delete(base_path() . "/" . Config::get('lfm.images_dir') . $base . "/" . "thumbs/" . $to_delete);
181-
182-
return "OK";
183-
}
184-
}
185-
} else
186-
{
187-
$file_name = base_path() . "/" . Config::get('lfm.images_dir') . $to_delete;
188-
if (File::isDirectory($file_name))
189-
{
190-
// make sure the directory is empty
191-
if (sizeof(File::files($file_name)) == 0)
192-
{
193-
File::deleteDirectory($file_name);
194-
195-
return "OK";
196-
} else
197-
{
198-
return "You cannot delete this folder because it is not empty!";
199-
}
200-
} else
201-
{
202-
if (File::exists($file_name))
203-
{
204-
File::delete($file_name);
205-
File::delete(base_path() . "/" . Config::get('lfm.images_dir') . "thumbs/" . $to_delete);
206-
207-
return "OK";
208-
}
209-
}
210-
}
211-
}
212-
213-
21470

21571
public function getFiles()
21672
{
21773
return "List of files";
21874
}
21975

76+
22077
/**
22178
* Get the images to load for a selected folder
22279
*

0 commit comments

Comments
 (0)