Skip to content

Commit e57731e

Browse files
committed
modify upload
1 parent 54ad713 commit e57731e

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

src/controllers/LfmController.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function __construct()
3636
}
3737

3838

39+
/*****************************
40+
*** Private Functions ***
41+
*****************************/
42+
43+
3944
private function setFilePath()
4045
{
4146
if ((Session::has('lfm_type')) && (Session::get('lfm_type') == 'Files')) {
@@ -78,6 +83,24 @@ private function checkSharedFolderExists()
7883
}
7984

8085

86+
/****************************
87+
*** Shared Functions ***
88+
****************************/
89+
90+
91+
public function getPath()
92+
{
93+
$working_dir = Input::get('working_dir');
94+
$path = base_path() . '/' . $this->file_location;
95+
96+
if (strlen($working_dir) !== '/') {
97+
$path .= $working_dir . '/';
98+
}
99+
100+
return $path;
101+
}
102+
103+
81104
public function getDirectories($path)
82105
{
83106
$thumb_folder_name = Config::get('lfm.thumb_folder_name');

src/controllers/UploadController.php

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,41 @@ public function upload()
2525
// sanity check
2626
if ( ! Input::hasFile('upload')) {
2727
// there ws no uploded file
28-
return "You must choose a file!";
29-
exit;
28+
return 'You must choose a file!';
3029
}
3130

3231
$file = Input::file('upload');
33-
$working_dir = Input::get('working_dir');
34-
$destinationPath = base_path() . "/" . $this->file_location;
3532

36-
if (strlen($working_dir) !== '/') {
37-
$destinationPath .= $working_dir . "/";
33+
$new_filename = $this->getNewName($file);
34+
35+
$destinationPath = parent::getPath();
36+
37+
if (File::exists($destinationPath . $new_filename)) {
38+
return 'A file with this name already exists!';
3839
}
3940

40-
$filename = $file->getClientOriginalName();
41-
$extension = $file->getClientOriginalExtension();
42-
$new_filename = $filename;
41+
$file->move($destinationPath, $new_filename);
4342

44-
if (Config::get('lfm.rename_file') === true) {
45-
$new_filename = uniqid() . "." . $extension;
43+
if (Session::get('lfm_type') == 'Images') {
44+
$this->makeThumb($destinationPath, $new_filename);
4645
}
4746

48-
if (File::exists($destinationPath . $new_filename)) {
49-
return "A file with this name already exists!";
50-
exit;
47+
if (Input::get('uploadMode') === 'express') {
48+
# code...
5149
}
5250

53-
Input::file('upload')->move($destinationPath, $new_filename);
51+
return 'OK';
52+
}
5453

55-
if (Session::get('lfm_type') == "Images") {
56-
$this->makeThumb($destinationPath, $new_filename);
54+
private function getNewName($file)
55+
{
56+
$new_filename = $file->getClientOriginalName();
57+
58+
if (Config::get('lfm.rename_file') === true) {
59+
$new_filename = uniqid() . '.' . $file->getClientOriginalExtension();
5760
}
5861

59-
return "OK";
62+
return $new_filename;
6063
}
6164

6265
private function makeThumb($destinationPath, $new_filename)

0 commit comments

Comments
 (0)