forked from gitbot/uguu
anti-dupe option
parent
b873b00865
commit
1d15881dee
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue