Skip to content

Commit 3aa9086

Browse files
Emmanuel BigChallengeEmmanuel BigChallenge
authored andcommitted
Multiple files upload + change translations (en/fr)
1 parent 975a8ef commit 3aa9086

File tree

5 files changed

+62
-44
lines changed

5 files changed

+62
-44
lines changed

src/controllers/UploadController.php

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,30 @@ public function upload()
3737
return $e->getMessage();
3838
}
3939

40-
$file = Input::file('upload');
40+
$files = Input::file('upload');
4141

42-
$new_filename = $this->getNewName($file);
42+
foreach($files as $file)
43+
{
44+
$new_filename = $this->getNewName($file);
4345

44-
$dest_path = parent::getPath('directory');
46+
$dest_path = parent::getPath('directory');
4547

46-
if (File::exists($dest_path . $new_filename)) {
47-
return Lang::get('laravel-filemanager::lfm.error-file-exist');
48-
}
48+
if (File::exists($dest_path . $new_filename)) {
49+
return Lang::get('laravel-filemanager::lfm.error-file-exist');
50+
}
4951

50-
$file->move($dest_path, $new_filename);
52+
$file->move($dest_path, $new_filename);
5153

52-
if ('Images' === $this->file_type) {
53-
$this->makeThumb($dest_path, $new_filename);
54-
}
54+
if ('Images' === $this->file_type) {
55+
$this->makeThumb($dest_path, $new_filename);
56+
}
5557

56-
Event::fire(new ImageWasUploaded(realpath($dest_path.'/'.$new_filename)));
58+
Event::fire(new ImageWasUploaded(realpath($dest_path.'/'.$new_filename)));
5759

58-
// upload via ckeditor 'Upload' tab
59-
if (!Input::has('show_list')) {
60-
return $this->useFile($new_filename);
60+
// upload via ckeditor 'Upload' tab
61+
if (!Input::has('show_list')) {
62+
return $this->useFile($new_filename);
63+
}
6164
}
6265

6366
return 'OK';
@@ -69,36 +72,51 @@ private function uploadValidator()
6972

7073
$expected_file_type = $this->file_type;
7174
$is_valid = false;
75+
$force_invalid = false;
7276

73-
$file = Input::file('upload');
74-
if (empty($file)) {
75-
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-file-empty'));
76-
}
77-
if (!$file instanceof UploadedFile) {
78-
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-instance'));
79-
}
77+
$files = Input::file('upload');
78+
79+
foreach($files as $file)
80+
{
81+
if (empty($file)) {
82+
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-file-empty'));
83+
}
84+
if (!$file instanceof UploadedFile) {
85+
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-instance'));
86+
}
8087

81-
$mimetype = $file->getMimeType();
88+
$mimetype = $file->getMimeType();
8289

83-
if ($expected_file_type === 'Files') {
84-
$config_name = 'lfm.valid_file_mimetypes';
85-
$valid_mimetypes = Config::get($config_name, $this->default_file_types);
86-
} else {
87-
$config_name = 'lfm.valid_image_mimetypes';
88-
$valid_mimetypes = Config::get($config_name, $this->default_image_types);
89-
}
90+
if ($expected_file_type === 'Files') {
91+
$config_name = 'lfm.valid_file_mimetypes';
92+
$valid_mimetypes = Config::get($config_name, $this->default_file_types);
93+
} else {
94+
$config_name = 'lfm.valid_image_mimetypes';
95+
$valid_mimetypes = Config::get($config_name, $this->default_image_types);
96+
}
9097

91-
if (!is_array($valid_mimetypes)) {
92-
throw new \Exception('Config : ' . $config_name . ' is not set correctly');
93-
}
98+
if (!is_array($valid_mimetypes)) {
99+
$force_invalid = true;
100+
throw new \Exception('Config : ' . $config_name . ' is not set correctly');
101+
}
94102

95-
if (in_array($mimetype, $valid_mimetypes)) {
96-
$is_valid = true;
103+
$is_valid = false;
104+
105+
if (in_array($mimetype, $valid_mimetypes)) {
106+
$is_valid = true;
107+
}
108+
109+
if (false === $is_valid) {
110+
$force_invalid = true;
111+
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-mime') . $mimetype);
112+
}
97113
}
98114

99-
if (false === $is_valid) {
100-
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-mime') . $mimetype);
115+
if($force_invalid)
116+
{
117+
return false;
101118
}
119+
102120
return $is_valid;
103121
}
104122

src/lang/en/lfm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
'title-page' => 'File Manager',
1818
'title-panel' => 'Laravel FileManager',
19-
'title-upload' => 'Upload File',
19+
'title-upload' => 'Upload File(s)',
2020
'title-view' => 'View File',
2121
'title-root' => 'Files',
2222
'title-shares' => 'Shared Files',
@@ -29,7 +29,7 @@
2929
'type-folder' => 'Folder',
3030

3131
'message-empty' => 'Folder is empty.',
32-
'message-choose' => 'Choose File',
32+
'message-choose' => 'Choose File(s)',
3333
'message-delete' => 'Are you sure you want to delete this item?',
3434
'message-name' => 'Folder name:',
3535
'message-rename' => 'Rename to:',
@@ -47,7 +47,7 @@
4747
'error-other' => 'An error has occured: ',
4848
'error-too-large' => 'Request entity too large!',
4949

50-
'btn-upload' => 'Upload File',
50+
'btn-upload' => 'Upload File(s)',
5151
'btn-uploading' => 'Uploading...',
5252
'btn-close' => 'Close',
5353
'btn-crop' => 'Crop',

src/lang/fr/lfm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
'title-page' => 'Gestionnaire de fichiers',
1818
'title-panel' => 'Laravel FileManager',
19-
'title-upload' => 'Envoyer un fichier',
19+
'title-upload' => 'Envoyer un/des fichier(s)',
2020
'title-view' => 'Voir le fichier',
2121
'title-root' => 'Fichiers',
2222
'title-shares' => 'Shared Files',
@@ -29,7 +29,7 @@
2929
'type-folder' => 'Dossier',
3030

3131
'message-empty' => 'Dossier est vide',
32-
'message-choose' => 'Choisir un fichier',
32+
'message-choose' => 'Choisir un/des fichier(s)',
3333
'message-delete' => 'Êtes-vous sûr de vouloir supprimer ce fichier ?',
3434
'message-name' => 'Nom du dossier:',
3535
'message-rename' => 'Renommer le dossier:',
@@ -45,7 +45,7 @@
4545
'error-instance' => 'The uploaded file should be an instance of UploadedFile',
4646
'error-invalid' => 'Invalid upload request',
4747

48-
'btn-upload' => 'Envoyer le fichier',
48+
'btn-upload' => 'Envoyer le/les fichier(s)',
4949
'btn-uploading' => 'Envoi...',
5050
'btn-close' => 'Fermer',
5151
'btn-crop' => 'Rogner',

src/views/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<label for='upload' class='control-label'>{{ Lang::get('laravel-filemanager::lfm.message-choose') }}</label>
115115
<div class="controls">
116116
<div class="input-group" style="width: 100%">
117-
<input type="file" id="upload" name="upload">
117+
<input type="file" id="upload" name="upload[]" multiple="multiple">
118118
</div>
119119
</div>
120120
</div>

src/views/script.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function showResponse(responseText, statusText, xhr, $form) {
5656
if (responseText != 'OK'){
5757
notify(responseText);
5858
}
59-
$('#upload').val('');
59+
$('input#upload').val('');
6060
loadItems();
6161
}
6262

0 commit comments

Comments
 (0)