44    public static function processZipFile($a_directory, $a_file, $structure, $ref_id = 
null, $containerType = 
null, $tree = 
null, $access_handler = 
null)
 
   50        self::$new_files = array();
 
   52        $pathinfo = pathinfo($a_file);
 
   53        $file = $pathinfo[
"basename"];
 
   56        if ($pathinfo[
"extension"] == 
"") {
 
   65        unlink($a_directory . 
"/" . $file);
 
   72        if (empty($filearray)) {
 
   77        foreach ($filearray[
"file"] as $key => $value) {
 
   79            if (substr($value, 0, 1) == 
"." || stristr($filearray[
"path"][$key], 
"/__MACOSX/")) {
 
   80                unlink($filearray[
"path"][$key] . $value);
 
   81                unset($filearray[
"path"][$key]);
 
   82                unset($filearray[
"file"][$key]);
 
   89                unlink($filearray[path][$key]);
 
  102            foreach (array_count_values($filearray[
"file"]) as $key => $value) {
 
  108            if (isset($doublettes)) {
 
  110                    $lng->txt(
"exc_upload_error") . 
"<br />" . 
$lng->txt(
"zip_structure_error") . $doublettes,
 
  115            $mac_dir = $a_directory . 
"/__MACOSX";
 
  116            if (file_exists($mac_dir)) {
 
  122        if ($ref_id != 
null) {
 
  144        $dirlist = opendir($dir);
 
  145        while (
false !== ($file = readdir($dirlist))) {
 
  146            if (!is_file($dir . 
"/" . $file) && !is_dir($dir . 
"/" . $file)) {
 
  150            if ($file != 
'.' && $file != 
'..') {
 
  151                $newpath = $dir . 
'/' . $file;
 
  152                $level = explode(
'/', $newpath);
 
  153                if (is_dir($newpath)) {
 
  156                    $arr[
"path"][] = $dir . 
"/";
 
  157                    $arr[
"file"][] = end($level);
 
  167    public static function createObjects($dir, $structure, $ref_id, $containerType, $tree = 
null, $access_handler = 
null)
 
  169        $dirlist = opendir($dir);
 
  171        while (
false !== ($file = readdir($dirlist))) {
 
  172            if (!is_file($dir . 
"/" . $file) && !is_dir($dir . 
"/" . $file)) {
 
  175            if ($file != 
'.' && $file != 
'..') {
 
  176                $newpath = $dir . 
'/' . $file;
 
  177                $level = explode(
'/', $newpath);
 
  178                if (is_dir($newpath)) {
 
  199        switch ($containerType) {
 
  201                include_once(
"./Modules/Category/classes/class.ilObjCategory.php");
 
  203                $newObj->setType(
"cat");
 
  207                include_once(
"./Modules/Folder/classes/class.ilObjFolder.php");
 
  209                $newObj->setType(
"fold");
 
  212            case "WorkspaceFolder":
 
  213                include_once(
"./Modules/WorkspaceFolder/classes/class.ilObjWorkspaceFolder.php");
 
  218        $newObj->setTitle(
$name);
 
  222        if (!$access_handler) {
 
  223            $newObj->createReference();
 
  224            $newObj->putInTree($ref_id);
 
  225            $newObj->setPermissions($ref_id);
 
  227            if ($newObj->getType() == 
"cat") {
 
  231                $newObj->addTranslation(
$name, 
"", 
$lng->getLangKey(), 
$lng->getLangKey());
 
  234            self::$new_files[$ref_id][] = $newObj;
 
  236            return $newObj->getRefId();
 
  239            $node_id = $tree->insertObject($ref_id, $newObj->getId());
 
  240            $access_handler->setPermissions($ref_id, $node_id);
 
  262        $rbacsystem = 
$DIC->rbac()->system();
 
  266        if (!$access_handler) {
 
  267            $permission = $rbacsystem->checkAccess(
"create", $ref_id, 
"file");
 
  269            $permission = $access_handler->checkAccess(
"create", 
"", $ref_id, 
"file");
 
  274            include_once(
"./Modules/File/classes/class.ilObjFile.php");
 
  276            $fileObj->setType(
'file');
 
  281            include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
 
  283            $fileObj->setFileSize(filesize($path . 
"/" . 
$filename));
 
  287            if (!$access_handler) {
 
  288                $fileObj->createReference();
 
  289                $fileObj->putInTree($ref_id);
 
  290                $fileObj->setPermissions($ref_id);
 
  292                self::$new_files[$ref_id][] = $fileObj;
 
  294                $node_id = $tree->insertObject($ref_id, $fileObj->getId());
 
  295                $access_handler->setPermissions($ref_id, $node_id);
 
  299            $fileObj->createDirectory();
 
  329        return (preg_match(
'%^(?: 
  330                        [\x09\x0A\x0D\x20-\x7E]            # ASCII 
  331                        | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte 
  332                        |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs 
  333                        | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte 
  334                        |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates 
  335                        |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3 
  336                        | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15 
  337                        |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16 
  338                        )*$%xs', $string)) ? $string : 
utf8_encode($string);
 
  352        $fh = fopen($filein, 
'rb');
 
  353        $fh2 = fopen($fileout, 
'wb');
 
  354        stream_filter_append($fh2, 
'convert.base64-decode');
 
  358            if ($chunk === 
false) {
 
  361            fwrite($fh2, $chunk);
 
  379        $fh = fopen($filein, 
'rb');
 
  380        $fh2 = fopen($fileout, 
'wb');
 
  381        stream_filter_append($fh2, 
'convert.base64-encode');
 
  384            $chunk = fgets($fh, 76);
 
  385            if ($chunk === 
false) {
 
  388            fwrite($fh2, $chunk);
 
  407        if (!file_exists(
$in) || !is_readable(
$in)) {
 
  410        if ((!file_exists(
$out) && !is_writable(dirname(
$out)) || (file_exists(
$out) && !is_writable(
$out)))) {
 
  414        $in_file = fopen(
$in, 
"rb");
 
  415        if (!$out_file = gzopen(
$out, 
"wb" . 
$param)) {
 
  419        while (!feof($in_file)) {
 
  420            $buffer = fgets($in_file, 4096);
 
  421            gzwrite($out_file, $buffer, 4096);
 
  442        if (!file_exists(
$in) || !is_readable(
$in)) {
 
  445        if ((!file_exists(
$out) && !is_writable(dirname(
$out)) || (file_exists(
$out) && !is_writable(
$out)))) {
 
  449        $in_file = gzopen(
$in, 
"rb");
 
  450        $out_file = fopen(
$out, 
"wb");
 
  452        while (!gzeof($in_file)) {
 
  453            $buffer = gzread($in_file, 4096);
 
  454            fwrite($out_file, $buffer, 4096);
 
  471        $finfo = 
new finfo(FILEINFO_MIME);
 
  473        return $finfo->buffer($content);
 
  484        if (!file_exists($a_file) or !is_readable($a_file)) {
 
  509        $setting = 
$DIC->settings();
 
  511        static $fileadmin_ref_id;
 
  513        if ($fileadmin_ref_id === 
null) {
 
  515            $id = (int) reset($objects_by_type)[
'obj_id'];
 
  517            $fileadmin_ref_id = (int) reset($references);
 
  519        if (
$DIC->rbac()->system()->checkAccess(
'upload_blacklisted_files', $fileadmin_ref_id)) {
 
  524        foreach (explode(
",", $setting->get(
"suffix_custom_expl_black")) as $blocked_suffix) {
 
  525            $blocked[] = trim(strtolower($blocked_suffix));
 
  527        $blocked = array_filter($blocked, 
function ($item) {
 
  544        $setting = 
$DIC->settings();
 
  550        foreach (explode(
",", $setting->get(
"suffix_repl_additional")) as $custom_black) {
 
  551            $custom_black = trim(strtolower($custom_black));
 
  552            if (($key = array_search($custom_black, $whitelist)) !== 
false) {
 
  553                unset($whitelist[$key]);
 
  558        foreach (explode(
",", $setting->get(
"suffix_custom_white_list")) as $custom_white) {
 
  559            $custom_white = trim(strtolower($custom_white));
 
  560            if (!in_array($custom_white, $whitelist)) {
 
  561                $whitelist[] = $custom_white;
 
  834        if (!self::hasValidExtension($a_filename)) {
 
  835            $pi = pathinfo($a_filename);
 
  837            $basename = str_replace(
".", 
"", $pi[
"basename"]);
 
  838            if (trim($basename) == 
"") {
 
  839                include_once(
"./Services/Utilities/classes/class.ilFileUtilsException.php");
 
  843            if ($pi[
"dirname"] != 
"" && ($pi[
"dirname"] != 
"." || substr($a_filename, 0, 2) == 
"./")) {
 
  844                $a_filename = $pi[
"dirname"] . 
"/" . $basename;
 
  846                $a_filename = $basename;
 
  861        $pi = pathinfo($a_filename);
 
  863        $extension = strtolower($pi[
"extension"]);
 
  865        if (preg_match(
'/^ph(p[3457]?|t|tml|ar)$/i', $extension)) {
 
  869        return in_array($extension, self::getValidExtensions())
 
  870            && !in_array($extension, self::getExplicitlyBlockedFiles());
 
  883    public static function rename($a_source, $a_target)
 
  885        $pi = pathinfo($a_target);
 
  886        if (!in_array(strtolower($pi[
"extension"]), self::getValidExtensions())) {
 
  887            include_once(
"./Services/Utilities/classes/class.ilFileUtilsException.php");
 
  891        return rename($a_source, $a_target);
 
if(php_sapi_name() !='cli') $in
An exception for terminatinating execution or to throw for unit testing.
Class to report exception.
fastGunzip($in, $out)
fast uncompressing the file with the zlib-extension without memory consumption
static getExplicitlyBlockedFiles()
static hasValidExtension($a_filename)
static createObjects($dir, $structure, $ref_id, $containerType, $tree=null, $access_handler=null)
static getValidFilename($a_filename)
Get valid filename.
static createContainer($name, $ref_id, $containerType, $tree=null, $access_handler=null)
static processZipFile($a_directory, $a_file, $structure, $ref_id=null, $containerType=null, $tree=null, $access_handler=null)
static utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
static getDefaultValidExtensionWhiteList()
Valid extensions.
static getValidExtensions()
Valid extensions.
fastBase64Encode($filein, $fileout)
decodes base encoded file row by row to prevent memory exhaust
static lookupContentMimeType($content)
static _lookupMimeType($a_file)
fastGZip($in, $out, $level="9")
fast compressing the file with the zlib-extension without memory consumption
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static createFile($filename, $path, $ref_id, $tree=null, $access_handler=null)
Creates and inserts file object into tree.
static fastBase64Decode($filein, $fileout)
decodes base encoded file row by row to prevent memory exhaust
static lookupFileMimeType($a_file)
static rename($a_source, $a_target)
Rename a file.
Class ilObjWorkspaceFolder.
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
static _getAllReferences($a_id)
get all reference ids of object
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled