Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 54 additions & 36 deletions src/controllers/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,30 @@ public function upload()
return $e->getMessage();
}

$file = Input::file('upload');
$files = Input::file('upload');

$new_filename = $this->getNewName($file);
foreach($files as $file)
{
$new_filename = $this->getNewName($file);

$dest_path = parent::getPath('directory');
$dest_path = parent::getPath('directory');

if (File::exists($dest_path . $new_filename)) {
return Lang::get('laravel-filemanager::lfm.error-file-exist');
}
if (File::exists($dest_path . $new_filename)) {
return Lang::get('laravel-filemanager::lfm.error-file-exist');
}

$file->move($dest_path, $new_filename);
$file->move($dest_path, $new_filename);

if ('Images' === $this->file_type) {
$this->makeThumb($dest_path, $new_filename);
}
if ('Images' === $this->file_type) {
$this->makeThumb($dest_path, $new_filename);
}

Event::fire(new ImageWasUploaded(realpath($dest_path.'/'.$new_filename)));
Event::fire(new ImageWasUploaded(realpath($dest_path.'/'.$new_filename)));

// upload via ckeditor 'Upload' tab
if (!Input::has('show_list')) {
return $this->useFile($new_filename);
// upload via ckeditor 'Upload' tab
if (!Input::has('show_list')) {
return $this->useFile($new_filename);
}
}

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

$expected_file_type = $this->file_type;
$is_valid = false;
$force_invalid = false;

$file = Input::file('upload');
if (empty($file)) {
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-file-empty'));
}
if (!$file instanceof UploadedFile) {
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-instance'));
}
$files = Input::file('upload');

foreach($files as $file)
{
if (empty($file)) {
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-file-empty'));
}
if (!$file instanceof UploadedFile) {
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-instance'));
}

$mimetype = $file->getMimeType();
$mimetype = $file->getMimeType();

if ($expected_file_type === 'Files') {
$config_name = 'lfm.valid_file_mimetypes';
$valid_mimetypes = Config::get($config_name, $this->default_file_types);
} else {
$config_name = 'lfm.valid_image_mimetypes';
$valid_mimetypes = Config::get($config_name, $this->default_image_types);
}
if ($expected_file_type === 'Files') {
$config_name = 'lfm.valid_file_mimetypes';
$valid_mimetypes = Config::get($config_name, $this->default_file_types);
} else {
$config_name = 'lfm.valid_image_mimetypes';
$valid_mimetypes = Config::get($config_name, $this->default_image_types);
}

if (!is_array($valid_mimetypes)) {
throw new \Exception('Config : ' . $config_name . ' is not set correctly');
}
if (!is_array($valid_mimetypes)) {
$force_invalid = true;
throw new \Exception('Config : ' . $config_name . ' is not set correctly');
}

if (in_array($mimetype, $valid_mimetypes)) {
$is_valid = true;
$is_valid = false;

if (in_array($mimetype, $valid_mimetypes)) {
$is_valid = true;
}

if (false === $is_valid) {
$force_invalid = true;
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-mime') . $mimetype);
}
}

if (false === $is_valid) {
throw new \Exception(Lang::get('laravel-filemanager::lfm.error-mime') . $mimetype);
if($force_invalid)
{
return false;
}

return $is_valid;
}

Expand Down
6 changes: 3 additions & 3 deletions src/lang/en/lfm.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'title-page' => 'File Manager',
'title-panel' => 'Laravel FileManager',
'title-upload' => 'Upload File',
'title-upload' => 'Upload File(s)',
'title-view' => 'View File',
'title-root' => 'Files',
'title-shares' => 'Shared Files',
Expand All @@ -29,7 +29,7 @@
'type-folder' => 'Folder',

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

'btn-upload' => 'Upload File',
'btn-upload' => 'Upload File(s)',
'btn-uploading' => 'Uploading...',
'btn-close' => 'Close',
'btn-crop' => 'Crop',
Expand Down
6 changes: 3 additions & 3 deletions src/lang/fr/lfm.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'title-page' => 'Gestionnaire de fichiers',
'title-panel' => 'Laravel FileManager',
'title-upload' => 'Envoyer un fichier',
'title-upload' => 'Envoyer un/des fichier(s)',
'title-view' => 'Voir le fichier',
'title-root' => 'Fichiers',
'title-shares' => 'Shared Files',
Expand All @@ -29,7 +29,7 @@
'type-folder' => 'Dossier',

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

'btn-upload' => 'Envoyer le fichier',
'btn-upload' => 'Envoyer le/les fichier(s)',
'btn-uploading' => 'Envoi...',
'btn-close' => 'Fermer',
'btn-crop' => 'Rogner',
Expand Down
2 changes: 1 addition & 1 deletion src/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<label for='upload' class='control-label'>{{ Lang::get('laravel-filemanager::lfm.message-choose') }}</label>
<div class="controls">
<div class="input-group" style="width: 100%">
<input type="file" id="upload" name="upload">
<input type="file" id="upload" name="upload[]" multiple="multiple">
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/views/script.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function showResponse(responseText, statusText, xhr, $form) {
if (responseText != 'OK'){
notify(responseText);
}
$('#upload').val('');
$('input#upload').val('');
loadItems();
}

Expand Down