Added duplicate uploads detection

This commit is contained in:
Marcin Kurczewski 2013-10-09 12:36:14 +02:00
parent 7b955883c9
commit f8ab508c06

View file

@ -149,7 +149,10 @@ class PostController
throw new SimpleException('Invalid file type "' . $mimeType . '"');
}
//todo: find out duplicate files
$fileHash = md5_file($suppliedFile['tmp_name']);
$duplicatedPost = R::findOne('post', 'file_hash = ?', [$fileHash]);
if ($duplicatedPost !== null)
throw new SimpleException('Duplicate upload');
do
{
@ -174,6 +177,8 @@ class PostController
$dbPost = R::dispense('post');
$dbPost->type = $postType;
$dbPost->name = $name;
$dbPost->orig_name = basename($suppliedFile['name']);
$dbPost->file_hash = $fileHash;
$dbPost->mime_type = $mimeType;
$dbPost->safety = $suppliedSafety;
$dbPost->upload_date = time();