Skip to content

Commit 7f07972

Browse files
committed
add work-around to fix file name emptified issue
1 parent 7bc9b19 commit 7f07972

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/Controllers/UploadController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ public function upload()
4646
$response = count($error_bag) > 0 ? $error_bag : parent::$success_response;
4747
} else { // upload via ckeditor5 expects json responses
4848
if (is_null($new_filename)) {
49-
$response = ['error' =>
50-
[
51-
'message' => $error_bag[0]
52-
]
53-
];
49+
$response = [
50+
'error' => [ 'message' => $error_bag[0] ]
51+
];
5452
} else {
5553
$url = $this->lfm->setName($new_filename)->url();
5654

src/Lfm.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,22 @@ public function config($key)
4646
*/
4747
public function getNameFromPath($path)
4848
{
49-
setlocale(LC_ALL, 'en_US.UTF-8');
50-
return pathinfo($path, PATHINFO_BASENAME);
49+
return $this->utf8Pathinfo($path, 'basename');
50+
}
51+
52+
public function utf8Pathinfo($path, $part_name)
53+
{
54+
// XXX: all locale work-around for issue: utf8 file name got emptified
55+
// if there's no '/', we're probably dealing with just a filename
56+
// so just put an 'a' in front of it
57+
if (strpos($path, '/') === false) {
58+
$path_parts = pathinfo('a' . $path);
59+
} else {
60+
$path = str_replace('/', '/a', $path);
61+
$path_parts = pathinfo($path);
62+
}
63+
64+
return substr($path_parts[$part_name], 1);
5165
}
5266

5367
public function allowFolderType($type)

src/LfmPath.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ private function uploadValidator($file)
277277

278278
private function getNewName($file)
279279
{
280-
setlocale(LC_ALL, 'en_US.UTF-8');
281-
$new_file_name = $this->helper
282-
->translateFromUtf8(trim(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME)));
280+
$new_file_name = $this->helper->translateFromUtf8(
281+
trim($this->helper->utf8Pathinfo($file->getClientOriginalName(), "filename"))
282+
);
283283

284284
$extension = $file->getClientOriginalExtension();
285285

0 commit comments

Comments
 (0)