function rm_recursive($filepath)
 {
     if (is_dir($filepath) && !is_link($filepath)) {
         if ($dh = opendir($filepath)) {
             while (($sf = readdir($dh)) !== false) {
                 if ($sf == '.' || $sf == '..') {
                     continue;
                 }
                 if (!UpgradeFunctions::rm_recursive($filepath . '/' . $sf)) {
                     //throw new Exception( $filepath.'/'.$sf.' could not be deleted.');
                     return false;
                 }
             }
             closedir($dh);
         }
         return rmdir($filepath);
     }
     return unlink($filepath);
 }
<?php

require_once "../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/upgrades/UpgradeFunctions.inc.php';
error_reporting(E_ALL);
UpgradeFunctions::setPermissionObject();