]> jfr.im git - uguu.git/blobdiff - static/php/upload.php
fixed empty db when not logging ip
[uguu.git] / static / php / upload.php
index 1be73dbf8a484a09772e480db43e1ff87d187804..6c6786b691cbedbbd0106f4ec401e6664e4c73ec 100644 (file)
@@ -22,8 +22,8 @@ function generateName($file)
     global $doubledots;
 
     // We start at N retries, and --N until we give up
-    $tries = POMF_FILES_RETRIES;
-    $length = POMF_FILES_LENGTH;
+    $tries = UGUU_FILES_RETRIES;
+    $length = UGUU_FILES_LENGTH;
     //Get EXT
     $ext = pathinfo($file->name, PATHINFO_EXTENSION);
     //Get mime
@@ -67,7 +67,6 @@ function generateName($file)
             exit(0);
           }
 
-
         //Check if EXT is blacklisted
         if (in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))) {
             http_response_code(415);           
@@ -75,17 +74,6 @@ function generateName($file)
             exit(0);
         }
 
-        // Check blacklist DB
-        $q = $db->prepare('SELECT hash, COUNT(*) AS count FROM blacklistedfiles WHERE hash = (:hash)');
-        $q->bindValue(':hash', $file->getSha1(), PDO::PARAM_STR);
-        $q->execute();
-        $result = $q->fetch();
-        if ($result['count'] > 0) {
-            http_response_code(415);
-            throw new UploadException(UPLOAD_ERR_BLACKLISTED);
-            exit(0);
-        }
-
         // Check if a file with the same name does already exist in the database
         $q = $db->prepare('SELECT COUNT(filename) FROM files WHERE filename = (:name)');
         $q->bindValue(':name', $name, PDO::PARAM_STR);
@@ -121,7 +109,7 @@ function uploadFile($file)
     $ip = $_SERVER['REMOTE_ADDR'];
 
     // Store the file's full file path in memory
-    $uploadFile = POMF_FILES_ROOT . $newname;
+    $uploadFile = UGUU_FILES_ROOT . $newname;
 
     // Attempt to move it to the static directory
     if (!move_uploaded_file($file->tempfile, $uploadFile)) {
@@ -145,7 +133,8 @@ function uploadFile($file)
     if(LOG_IP == 'yes'){
         $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, ip) VALUES (:hash, :orig, :name, :size, :date, :ip)');
     }else{
-           $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date) VALUES (:hash, :orig, :name, :size, :date)');
+        $ip = '0';
+        $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, ip) VALUES (:hash, :orig, :name, :size, :date, :ip)');
     }
     // Common parameters binding
     $q->bindValue(':hash', $file->getSha1(), PDO::PARAM_STR);
@@ -153,15 +142,13 @@ function uploadFile($file)
     $q->bindValue(':name', $newname, PDO::PARAM_STR);
     $q->bindValue(':size', $file->size, PDO::PARAM_INT);
     $q->bindValue(':date', time(), PDO::PARAM_INT);
-    if(LOG_IP == 'yes'){
     $q->bindValue(':ip', $ip, PDO::PARAM_STR);
-    }
     $q->execute();
 
     return array(
         'hash' => $file->getSha1(),
         'name' => $file->name,
-        'url' => POMF_URL.rawurlencode($newname),
+        'url' => UGUU_URL.rawurlencode($newname),
         'size' => $file->size,
     );
 }