66use Illuminate \Support \Facades \Input ;
77use Illuminate \Support \Facades \Session ;
88use Illuminate \Support \Facades \View ;
9- use Illuminate \Support \Str ;
109use 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