Skip to content

Commit ccab146

Browse files
authored
Refactor code.
File name code refactor.
1 parent b5d85cf commit ccab146

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/FilesUploadAndImageResize.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,9 @@ public function uploadFiles(string $fileParamName, int $minImgWidth = 400, array
166166
$this->s++;
167167

168168
$fileInfo = pathinfo(basename($_FILES[$fileParamName]['name'][$this->n]), PATHINFO_EXTENSION);
169-
$filesName = str_replace(" ", "", trim($_FILES[$fileParamName]['name'][$this->n]));
170-
$files = explode(".", $filesName);
171-
$File_Ext = substr($_FILES[$fileParamName]['name'][$this->n], strrpos($_FILES[$fileParamName]['name'][$this->n], '.'));
172-
169+
$fileName = 'file-' . $this->s . '-' . rand(0, 999) . time() . '.' . $fileInfo;
173170
if ($reName != "") {
174-
$fileName = $this->s . $reName . $File_Ext;
175-
} else {
176-
if (count($files) > 2) {
177-
array_pop($files);
178-
$fileName = implode(".", $files) . $File_Ext;
179-
} else {
180-
$fileName = $files[0] . $File_Ext;
181-
}
171+
$fileName = $this->s . $reName . '.' . $fileInfo;
182172
}
183173
$filePath = trim($srcPath . $fileName);
184174
if (in_array(strtolower($fileInfo), array_map('strtolower', $this->allowExtension)) || empty($this->allowExtension)) {

0 commit comments

Comments
 (0)