Skip to content

Commit e94c08e

Browse files
authored
Merge pull request #23 from WebFiori/dev
fix: Fix of Changing File Name When Uploaded
2 parents 6e8ff77 + 26bbe0d commit e94c08e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

webfiori/file/FileUploader.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ private function getFileArr($fileOrFiles,$replaceIfExist, $idx = null): array {
463463
$errIdx = 'error';
464464
$tempIdx = 'tmp_name';
465465
$fileInfoArr = [];
466-
$fileInfoArr[UploaderConst::NAME_INDEX] = $idx === null ? filter_var($fileOrFiles[UploaderConst::NAME_INDEX], FILTER_SANITIZE_FULL_SPECIAL_CHARS) : filter_var($fileOrFiles[UploaderConst::NAME_INDEX][$idx], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
466+
$fileInfoArr[UploaderConst::NAME_INDEX] = $idx === null ? filter_var($fileOrFiles[UploaderConst::NAME_INDEX]) : filter_var($fileOrFiles[UploaderConst::NAME_INDEX][$idx]);
467467
$fileInfoArr[UploaderConst::SIZE_INDEX] = $idx === null ? filter_var($fileOrFiles[UploaderConst::SIZE_INDEX], FILTER_SANITIZE_NUMBER_INT) : filter_var($fileOrFiles[UploaderConst::SIZE_INDEX][$idx], FILTER_SANITIZE_NUMBER_INT);
468468
$fileInfoArr[UploaderConst::PATH_INDEX] = $this->getUploadDir();
469469
$fileInfoArr[UploaderConst::ERR_INDEX] = '';
@@ -478,15 +478,17 @@ private function getFileArr($fileOrFiles,$replaceIfExist, $idx = null): array {
478478
if (File::isDirectory($this->getUploadDir())) {
479479
$filePath = $this->getUploadDir().'\\'.$fileInfoArr[UploaderConst::NAME_INDEX];
480480
$filePath = str_replace('\\', '/', $filePath);
481-
481+
482+
//If in CLI, use copy (testing env)
483+
$moveFunc = http_response_code() === false ? 'copy' : 'move_uploaded_file';
484+
482485
if (!File::isFileExist($filePath)) {
483486
$fileInfoArr[UploaderConst::EXIST_INDEX] = false;
484487
$fileInfoArr[UploaderConst::REPLACE_INDEX] = false;
485488
$name = $idx === null ? $fileOrFiles[$tempIdx] : $fileOrFiles[$tempIdx][$idx];
486-
$sanitizedName = filter_var($name, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
489+
$sanitizedName = filter_var($name);
490+
487491

488-
//If in CLI, use copy (testing env)
489-
$moveFunc = http_response_code() === false ? 'copy' : 'move_uploaded_file';
490492

491493
if (!($moveFunc($sanitizedName, $filePath))) {
492494
$fileInfoArr[UploaderConst::ERR_INDEX] = UploaderConst::ERR_MOVE_TEMP;
@@ -500,9 +502,9 @@ private function getFileArr($fileOrFiles,$replaceIfExist, $idx = null): array {
500502
$fileInfoArr[UploaderConst::REPLACE_INDEX] = true;
501503
unlink($filePath);
502504
$name = $idx === null ? $fileOrFiles[$tempIdx] : $fileOrFiles[$tempIdx][$idx];
503-
$sanitizedName = $sanitizedName = filter_var($name, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
505+
$sanitizedName = $sanitizedName = filter_var($name);
504506

505-
if (move_uploaded_file($sanitizedName, $filePath)) {
507+
if ($moveFunc($sanitizedName, $filePath)) {
506508
$fileInfoArr[UploaderConst::UPLOADED_INDEX] = true;
507509
} else {
508510
$fileInfoArr[UploaderConst::UPLOADED_INDEX] = false;

0 commit comments

Comments
 (0)