From 19a3645c2415bbe45c0a6cadd003d7b3ef04a630 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Sun, 29 May 2016 13:39:25 +0000 Subject: upload.php: Don't unlink() tempfiles in upload_file() We don't need to care about garbage collection and explicitly unlinking temporary files: PHP will handle that for us automatically. In other words, this is "dead" code. Less code the better. Updates the comment before it to reflect this. Tested on PHP 5.6.22 and PHP 7.0.7 on Debian stretch/sid GNU/Linux. Tested-by: Juuso Lapinlampi See: https://secure.php.net/manual/en/function.tmpfile.php --- static/upload.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'static') diff --git a/static/upload.php b/static/upload.php index ebedeab..4b1f73d 100644 --- a/static/upload.php +++ b/static/upload.php @@ -112,8 +112,9 @@ function upload_file($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, delete the file just uploaded and return the proper link and data. + // 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. $q = $db->prepare('SELECT filename, COUNT(*) AS count FROM files WHERE hash = (:hash) '. 'AND size = (:size)'); $q->bindValue(':hash', $file->get_sha1(), PDO::PARAM_STR); @@ -121,8 +122,6 @@ function upload_file($file) $q->execute(); $result = $q->fetch(); if ($result['count'] > 0) { - unlink($file->tempfile); - return array( 'hash' => $file->get_sha1(), 'name' => $file->name, -- cgit v1.2.3