anti-dupe option

testing
nokonoko 2021-06-22 11:39:26 +02:00
parent b873b00865
commit 1d15881dee
2 changed files with 23 additions and 0 deletions

View File

@ -33,6 +33,9 @@ define('UGUU_ADMIN_PASS', '$2y$12$.NHW25QBD/XPSYkNe6tEtObwEXsJeiQIo3xWidU.21ECkF
/** Log IP of uploads */
define('LOG_IP', 'no');
/** Anti-dupe files */
define('UGUU_DUPE', 'false');
/*
* File system location where to store uploaded files
*

View File

@ -102,6 +102,26 @@ function uploadFile($file)
throw new UploadException($file->error);
}
// Check if a file with the same hash and size (a file which is the same)
// does already exist in the database; if it does, return the proper link
// and data. PHP deletes the temporary file just uploaded automatically.
if(UGUU_DUPE == 'true'){
$q = $db->prepare('SELECT filename, COUNT(*) AS count FROM files WHERE hash = (:hash) '.
'AND size = (:size)');
$q->bindValue(':hash', $file->getSha1(), PDO::PARAM_STR);
$q->bindValue(':size', $file->size, PDO::PARAM_INT);
$q->execute();
$result = $q->fetch();
if ($result['count'] > 0) {
return [
'hash' => $file->getSha1(),
'name' => $file->name,
'url' => UGUU_URL.rawurlencode($result['filename']),
'size' => $file->size,
];
}
}
// Generate a name for the file
$newname = generateName($file);