mirror of
https://github.com/Rouji/single_php_filehost.git
synced 2025-04-05 00:49:33 +00:00
prevent filename collisions
This commit is contained in:
parent
9ceb65a05c
commit
626a227f76
11
index.php
11
index.php
@ -112,9 +112,14 @@ function storeFile($name, $tmpFile, $formatted = false)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ext = getExtension($name);
|
$ext = getExtension($name);
|
||||||
$id = rndStr($ID_LENGTH);
|
$len = $ID_LENGTH;
|
||||||
$basename = $id . '.' . $ext;
|
do //generate filenames until we get one, that doesn't already exist
|
||||||
$target_file = $STORE_PATH . $basename;
|
{
|
||||||
|
$id = rndStr($len++);
|
||||||
|
$basename = $id . '.' . $ext;
|
||||||
|
$target_file = $STORE_PATH . $basename;
|
||||||
|
} while (file_exists($target_file));
|
||||||
|
|
||||||
$res = move_uploaded_file($tmpFile, $target_file);
|
$res = move_uploaded_file($tmpFile, $target_file);
|
||||||
if ($res)
|
if ($res)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user