summaryrefslogtreecommitdiff
path: root/static/php
diff options
context:
space:
mode:
Diffstat (limited to 'static/php')
-rw-r--r--static/php/upload.php31
1 files changed, 10 insertions, 21 deletions
diff --git a/static/php/upload.php b/static/php/upload.php
index 82325d7..1bc74c9 100644
--- a/static/php/upload.php
+++ b/static/php/upload.php
@@ -85,25 +85,28 @@ function uploadFile($file)
throw new UploadException($file->error);
}
+ // Check mime type of a file
+ $finfo = new finfo(FILEINFO_MIME_TYPE);
+ $file->mime = $finfo->file($file->tempfile);
+
// Check if mime type is blocked
if (!empty($FILTER_MIME)) {
if ($FILTER_MODE == true) { //whitelist mode
if (!in_array($file->mime, $FILTER_MIME)) {
throw new UploadException(UPLOAD_ERR_EXTENSION);
}
- } else { //blacklist mode
+ } else { // blacklist mode
if (in_array($file->mime, $FILTER_MIME)) {
throw new UploadException(UPLOAD_ERR_EXTENSION);
}
}
}
-
// 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 = $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();
@@ -140,27 +143,15 @@ function uploadFile($file)
}
// Add it to the database
- if (empty($_SESSION['id'])) {
- // Query if user is NOT logged in
- $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, ' .
- 'expire, delid) VALUES (:hash, :orig, :name, :size, :date, ' .
- ':exp, :del)');
- } else {
- // Query if user is logged in (insert user id together with other data)
- $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, ' .
- 'expire, delid, user) VALUES (:hash, :orig, :name, :size, :date, ' .
- ':exp, :del, :user)');
- $q->bindValue(':user', $_SESSION['id'], PDO::PARAM_INT);
- }
+ $q = $db->prepare('INSERT INTO files (hash, originalname, filename, ' .
+ 'mime, size) VALUES (:hash, :orig, :name, :mime, :size)');
// Common parameters binding
$q->bindValue(':hash', $file->getSha1(), PDO::PARAM_STR);
$q->bindValue(':orig', strip_tags($file->name), PDO::PARAM_STR);
$q->bindValue(':name', $newname, PDO::PARAM_STR);
+ $q->bindValue(':mime', $file->mime, PDO::PARAM_STR);
$q->bindValue(':size', $file->size, PDO::PARAM_INT);
- $q->bindValue(':date', date('Y-m-d'), PDO::PARAM_STR);
- $q->bindValue(':exp', null, PDO::PARAM_STR);
- $q->bindValue(':del', sha1($file->tempfile), PDO::PARAM_STR);
$q->execute();
return array(
@@ -206,11 +197,9 @@ function refiles($files)
foreach ($files as $file) {
$f = new UploadedFile();
$f->name = $file['name'];
- $f->mime = $file['type'];
$f->size = $file['size'];
$f->tempfile = $file['tmp_name'];
$f->error = $file['error'];
- //$f->expire = $file['expire'];
$result[] = $f;
}