function deleteRedundantFiles()
{
    // check for any files to delete
    $nextCheck = trim(SITE_CONFIG_NEXT_CHECK_FOR_FILE_REMOVALS);
    if (strlen($nextCheck) == 0) {
        $nextCheck = time();
    }
    // dont run the check if we're not due to yet
    if ($nextCheck > time()) {
        return false;
    }
    // connect db
    $db = Database::getDatabase(true);
    // file removal periods
    $fileRemovalFreeAcc = trim(SITE_CONFIG_FREE_USER_UPLOAD_REMOVAL_DAYS);
    $fileRemovalPaidAcc = trim(SITE_CONFIG_PREMIUM_USER_UPLOAD_REMOVAL_DAYS);
    // set a maximum of 5 years otherwise we hit unix timestamp calculation issues
    if ($fileRemovalFreeAcc > 1825) {
        $fileRemovalFreeAcc = 1825;
    }
    if ($fileRemovalPaidAcc > 1825) {
        $fileRemovalPaidAcc = 1825;
    }
    // free/non-accounts
    if ((int) $fileRemovalFreeAcc != 0) {
        $sQL = 'SELECT file.id ';
        $sQL .= 'FROM file LEFT JOIN users ';
        $sQL .= 'ON file.userId = users.id ';
        $sQL .= 'WHERE file.statusId = 1 AND ';
        $sQL .= 'UNIX_TIMESTAMP(file.uploadedDate) < ' . strtotime('-' . $fileRemovalFreeAcc . ' days') . ' AND ';
        $sQL .= '(UNIX_TIMESTAMP(file.lastAccessed) < ' . strtotime('-' . $fileRemovalFreeAcc . ' days') . ' OR file.lastAccessed IS NULL) ';
        $sQL .= 'AND (file.userId IS NULL OR users.level = \'free user\');';
        $rows = $db->getRows($sQL);
        if (is_array($rows)) {
            foreach ($rows as $row) {
                // load file object
                $file = file::loadById($row['id']);
                if ($file) {
                    // remove file
                    $file->removeBySystem();
                }
            }
        }
    }
    // paid accounts
    if ((int) $fileRemovalPaidAcc != 0) {
        $sQL = 'SELECT file.id ';
        $sQL .= 'FROM file LEFT JOIN users ';
        $sQL .= 'ON file.userId = users.id ';
        $sQL .= 'WHERE file.statusId = 1 AND ';
        $sQL .= 'UNIX_TIMESTAMP(file.uploadedDate) < ' . strtotime('-' . $fileRemovalPaidAcc . ' days') . ' AND ';
        $sQL .= '(UNIX_TIMESTAMP(file.lastAccessed) < ' . strtotime('-' . $fileRemovalPaidAcc . ' days') . ' OR file.lastAccessed IS NULL) ';
        $sQL .= 'AND (users.level = \'admin\' OR users.level = \'paid user\');';
        $rows = $db->getRows($sQL);
        if (is_array($rows)) {
            foreach ($rows as $row) {
                // load file object
                $file = file::loadById($row['id']);
                if ($file) {
                    // remove file
                    $file->removeBySystem();
                }
            }
        }
    }
    // update db for next check. Run file check again in 1 hour.
    $nextCheck = time() + 60 * 60;
    $db->query('UPDATE site_config SET config_value = :newValue WHERE config_key = \'next_check_for_file_removals\'', array('newValue' => $nextCheck));
}
<?php

require_once 'ajax_auth.inc.php';
$db = Database::getDatabase();
$id = (int) $_REQUEST['id'];
$statusId = (int) $_REQUEST['statusId'];
// check for removal
if ($statusId == 3) {
    // load file
    $file = file::loadById($id);
    if (!$file) {
        die("0");
    }
    // remove
    $file->removeBySystem();
}
$db->query('UPDATE file SET statusId = :statusId WHERE id = :id', array('statusId' => $statusId, 'id' => $id));
if ($db->affectedRows() == 1) {
    die("1");
}
die("0");
<?php

/* setup includes */
require_once 'includes/master.inc.php';
/* require login */
$Auth->requireUser('login.php');
/* load file */
if (isset($_REQUEST['u'])) {
    $file = file::loadById($_REQUEST['u']);
    if (!$file) {
        // failed lookup of file
        redirect('http://' . _CONFIG_SITE_FULL_URL . '/account_home.' . SITE_CONFIG_PAGE_EXTENSION);
    }
    // check current user has permission to edit file
    if ($file->userId != $Auth->id) {
        redirect('http://' . _CONFIG_SITE_FULL_URL . '/account_home.' . SITE_CONFIG_PAGE_EXTENSION);
    }
} else {
    redirect('http://' . _CONFIG_SITE_FULL_URL . '/account_home.' . SITE_CONFIG_PAGE_EXTENSION);
}
/* setup page */
define("PAGE_NAME", t("edit_page_name", "Edit"));
define("PAGE_DESCRIPTION", t("edit_meta_description", "Edit existing item"));
define("PAGE_KEYWORDS", t("edit_meta_keywords", "edit, existing, item"));
/* handle submission */
if ((int) $_REQUEST['submitme']) {
    // validation
    $filename = trim($_REQUEST['filename']);
    $reset_stats = (int) trim($_REQUEST['reset_stats']);
    $folder = (int) trim($_REQUEST['folder']);
    if (!strlen($filename)) {