mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-15 16:58:42 +00:00
imrpove code
This commit is contained in:
parent
819734daca
commit
08ce435c7c
|
|
@ -249,18 +249,21 @@ class UploadFile
|
||||||
$limit = -1;
|
$limit = -1;
|
||||||
$fileName = '';
|
$fileName = '';
|
||||||
|
|
||||||
$nameWithoutExtension = empty($tempName) ? '' : \substr($tempName, 0, -\strlen($extension) - 1);
|
$nameWithoutExtension = empty($tempName)
|
||||||
|
? ''
|
||||||
|
: (empty($extension)
|
||||||
|
? $tempName
|
||||||
|
: \substr($tempName, 0, -\strlen($extension) - 1)
|
||||||
|
);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
++$limit;
|
++$limit;
|
||||||
$sha = empty($nameWithoutExtension) ? \sha1($tempName . $rnd) : $nameWithoutExtension . (empty($rnd) ? '' : '_' . $rnd);
|
$tempName = empty($nameWithoutExtension)
|
||||||
|
? \sha1($tempName . $rnd)
|
||||||
|
: $nameWithoutExtension . (empty($rnd) ? '' : '_' . $rnd);
|
||||||
|
|
||||||
if ($sha === false) {
|
$tempName .= !empty($extension) ? '.' . $extension : '';
|
||||||
throw new \Exception('No file path could be found. Potential attack!');
|
$fileName = $tempName;
|
||||||
}
|
|
||||||
|
|
||||||
$sha .= '.' . $extension;
|
|
||||||
$fileName = $sha;
|
|
||||||
$rnd = (string) \mt_rand();
|
$rnd = (string) \mt_rand();
|
||||||
} while (\is_file($path . '/' . $fileName) && $limit < self::PATH_GENERATION_LIMIT);
|
} while (\is_file($path . '/' . $fileName) && $limit < self::PATH_GENERATION_LIMIT);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user