summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorJuuso Lapinlampi <wub@partyvan.eu>2016-05-29 15:39:25 +0200
committerJuuso Lapinlampi <wub@partyvan.eu>2016-05-29 15:48:46 +0200
commit19a3645c2415bbe45c0a6cadd003d7b3ef04a630 (patch)
treec790022f0409bd5a80c55c17d8f0c7706eca9203 /static
parent2a998798c143460c4137e1c1b575cc28d7dd69d2 (diff)
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 <wub@partyvan.eu> See: https://secure.php.net/manual/en/function.tmpfile.php
Diffstat (limited to 'static')
-rw-r--r--static/upload.php7
1 files changed, 3 insertions, 4 deletions
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,