mirror of
https://github.com/Rouji/single_php_filehost.git
synced 2025-04-03 16:09:33 +00:00
up the filename length only after multiple collisions
This commit is contained in:
parent
5e0af0eb61
commit
3110662020
19
index.php
19
index.php
@ -116,13 +116,20 @@ function storeFile($name, $tmpFile, $formatted = false)
|
||||
}
|
||||
|
||||
$ext = getExtension($name);
|
||||
$len = $ID_LENGTH;
|
||||
do //generate filenames until we get one, that doesn't already exist
|
||||
$tries_per_len=3; //try random names a few times before upping the length
|
||||
for ($len = $ID_LENGTH; ; ++$len)
|
||||
{
|
||||
$id = rndStr($len++);
|
||||
$basename = $id . (empty($ext) ? '' : '.' . $ext);
|
||||
$target_file = $STORE_PATH . $basename;
|
||||
} while (file_exists($target_file));
|
||||
echo $len;
|
||||
for ($n=0; $n<=$tries_per_len; ++$n)
|
||||
{
|
||||
$id = rndStr($len);
|
||||
$basename = $id . (empty($ext) ? '' : '.' . $ext);
|
||||
$target_file = $STORE_PATH . $basename;
|
||||
|
||||
if (!file_exists($target_file))
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
|
||||
$res = move_uploaded_file($tmpFile, $target_file);
|
||||
if ($res)
|
||||
|
Loading…
Reference in New Issue
Block a user