Skip to content

Commit bf2513a

Browse files
committed
Add support for files with UTF-8 start letter
1 parent 444a7e7 commit bf2513a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

server/php/UploadHandler.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class UploadHandler
4343
function __construct($options = null, $initialize = true, $error_messages = null) {
4444
$this->response = array();
4545
$this->options = array(
46-
'script_url' => $this->get_full_url().'/'.basename($this->get_server_var('SCRIPT_NAME')),
46+
'script_url' => $this->get_full_url().'/'.$this->basename($this->get_server_var('SCRIPT_NAME')),
4747
'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/files/',
4848
'upload_url' => $this->get_full_url().'/files/',
4949
'input_stream' => 'php://input',
@@ -517,7 +517,7 @@ protected function trim_file_name($file_path, $name, $size, $type, $error,
517517
// Remove path information and dots around the filename, to prevent uploading
518518
// into different directories or replacing hidden system files.
519519
// Also remove control characters and spaces (\x00..\x20) around the filename:
520-
$name = trim(basename(stripslashes($name)), ".\x00..\x20");
520+
$name = trim($this->basename(stripslashes($name)), ".\x00..\x20");
521521
// Use a timestamp for empty filenames:
522522
if (!$name) {
523523
$name = str_replace('.', '-', microtime(true));
@@ -1150,7 +1150,7 @@ protected function handle_form_data($file, $index) {
11501150
}
11511151

11521152
protected function get_version_param() {
1153-
return basename(stripslashes($this->get_query_param('version')));
1153+
return $this->basename(stripslashes($this->get_query_param('version')));
11541154
}
11551155

11561156
protected function get_singular_param_name() {
@@ -1159,7 +1159,7 @@ protected function get_singular_param_name() {
11591159

11601160
protected function get_file_name_param() {
11611161
$name = $this->get_singular_param_name();
1162-
return basename(stripslashes($this->get_query_param($name)));
1162+
return $this->basename(stripslashes($this->get_query_param($name)));
11631163
}
11641164

11651165
protected function get_file_names_params() {
@@ -1168,7 +1168,7 @@ protected function get_file_names_params() {
11681168
return null;
11691169
}
11701170
foreach ($params as $key => $value) {
1171-
$params[$key] = basename(stripslashes($value));
1171+
$params[$key] = $this->basename(stripslashes($value));
11721172
}
11731173
return $params;
11741174
}
@@ -1385,4 +1385,8 @@ public function delete($print_response = true) {
13851385
return $this->generate_response($response, $print_response);
13861386
}
13871387

1388+
private function basename($filepath, $suffix = null) {
1389+
$splited = preg_split('/\//', rtrim ($filepath, '/ '));
1390+
return substr(basename('X'.$splited[count($splited)-1], $suffix), 1);
1391+
}
13881392
}

0 commit comments

Comments
 (0)