62    public static function processZipFile($a_directory, $a_file, $structure, $ref_id = 
null, $containerType = 
null, 
$tree = 
null, $access_handler = 
null)
 
   68        self::$new_files = array();
 
   70        $pathinfo = pathinfo($a_file);
 
   71        $file = $pathinfo[
"basename"];
 
   74        if ($pathinfo[
"extension"] == 
"") {
 
   81        ilUtil::moveUploadedFile($a_file, $file, $a_directory . 
"/" . $file);
 
   83        unlink($a_directory . 
"/" . $file);
 
   90        if (empty($filearray)) {
 
   95        foreach ($filearray[
"file"] as 
$key => $value) {
 
   97            if (substr($value, 0, 1) == 
"." || stristr($filearray[
"path"][
$key], 
"/__MACOSX/")) {
 
   98                unlink($filearray[
"path"][
$key] . $value);
 
   99                unset($filearray[
"path"][
$key]);
 
  100                unset($filearray[
"file"][
$key]);
 
  107                unlink($filearray[path][
$key]);
 
  120            foreach (array_count_values($filearray[
"file"]) as 
$key => $value) {
 
  126            if (isset($doublettes)) {
 
  128                    $lng->txt(
"exc_upload_error") . 
"<br />" . 
$lng->txt(
"zip_structure_error") . $doublettes,
 
  133            $mac_dir = $a_directory . 
"/__MACOSX";
 
  134            if (file_exists($mac_dir)) {
 
  140        if ($ref_id != 
null) {
 
  162        $dirlist = opendir($dir);
 
  163        while (
false !== ($file = readdir($dirlist))) {
 
  164            if (!is_file($dir . 
"/" . $file) && !is_dir($dir . 
"/" . $file)) {
 
  168            if ($file != 
'.' && $file != 
'..') {
 
  169                $newpath = $dir . 
'/' . $file;
 
  170                $level = explode(
'/', $newpath);
 
  171                if (is_dir($newpath)) {
 
  174                    $arr[
"path"][] = $dir . 
"/";
 
  175                    $arr[
"file"][] = end($level);
 
  198    public static function createObjects($dir, $structure, $ref_id, $containerType, 
$tree = 
null, $access_handler = 
null)
 
  200        $dirlist = opendir($dir);
 
  202        while (
false !== ($file = readdir($dirlist))) {
 
  203            if (!is_file($dir . 
"/" . $file) && !is_dir($dir . 
"/" . $file)) {
 
  206            if ($file != 
'.' && $file != 
'..') {
 
  207                $newpath = $dir . 
'/' . $file;
 
  208                $level = explode(
'/', $newpath);
 
  209                if (is_dir($newpath)) {
 
  238        switch ($containerType) {
 
  240                include_once(
"./Modules/Category/classes/class.ilObjCategory.php");
 
  242                $newObj->setType(
"cat");
 
  246                include_once(
"./Modules/Folder/classes/class.ilObjFolder.php");
 
  248                $newObj->setType(
"fold");
 
  251            case "WorkspaceFolder":
 
  252                include_once(
"./Modules/WorkspaceFolder/classes/class.ilObjWorkspaceFolder.php");
 
  257        $newObj->setTitle(
$name);
 
  261        if (!$access_handler) {
 
  262            $newObj->createReference();
 
  263            $newObj->putInTree($ref_id);
 
  264            $newObj->setPermissions($ref_id);
 
  266            if ($newObj->getType() == 
"cat") {
 
  270                $newObj->addTranslation(
$name, 
"", 
$lng->getLangKey(), 
$lng->getLangKey());
 
  273            self::$new_files[$ref_id][] = $newObj;
 
  275            return $newObj->getRefId();
 
  278            $node_id = 
$tree->insertObject($ref_id, $newObj->getId());
 
  279            $access_handler->setPermissions($ref_id, $node_id);
 
  300        $rbacsystem = 
$DIC->rbac()->system();
 
  304        if (!$access_handler) {
 
  305            $permission = $rbacsystem->checkAccess(
"create", $ref_id, 
"file");
 
  307            $permission = $access_handler->checkAccess(
"create", 
"", $ref_id, 
"file");
 
  312            include_once(
"./Modules/File/classes/class.ilObjFile.php");
 
  314            $fileObj->setType(
'file');
 
  319            include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
 
  325            if (!$access_handler) {
 
  326                $fileObj->createReference();
 
  327                $fileObj->putInTree($ref_id);
 
  328                $fileObj->setPermissions($ref_id);
 
  330                self::$new_files[$ref_id][] = $fileObj;
 
  332                $node_id = 
$tree->insertObject($ref_id, $fileObj->getId());
 
  333                $access_handler->setPermissions($ref_id, $node_id);
 
  337            $fileObj->createDirectory();
 
  367        return (preg_match(
'%^(?: 
  368                        [\x09\x0A\x0D\x20-\x7E]            # ASCII 
  369                        | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte 
  370                        |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs 
  371                        | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte 
  372                        |  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates 
  373                        |  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3 
  374                        | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15 
  375                        |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16 
  376                        )*$%xs', $string)) ? $string : 
utf8_encode($string);
 
  390        $fh = fopen($filein, 
'rb');
 
  391        $fh2 = fopen($fileout, 
'wb');
 
  392        stream_filter_append($fh2, 
'convert.base64-decode');
 
  396            if ($chunk === 
false) {
 
  399            fwrite($fh2, $chunk);
 
  417        $fh = fopen($filein, 
'rb');
 
  418        $fh2 = fopen($fileout, 
'wb');
 
  419        stream_filter_append($fh2, 
'convert.base64-encode');
 
  422            $chunk = fgets($fh, 76);
 
  423            if ($chunk === 
false) {
 
  426            fwrite($fh2, $chunk);
 
  445        if (!file_exists(
$in) || !is_readable(
$in)) {
 
  448        if ((!file_exists(
$out) && !is_writable(dirname(
$out)) || (file_exists(
$out) && !is_writable(
$out)))) {
 
  452        $in_file = fopen(
$in, 
"rb");
 
  453        if (!$out_file = gzopen(
$out, 
"wb" . $param)) {
 
  457        while (!feof($in_file)) {
 
  458            $buffer = fgets($in_file, 4096);
 
  459            gzwrite($out_file, $buffer, 4096);
 
  480        if (!file_exists(
$in) || !is_readable(
$in)) {
 
  483        if ((!file_exists(
$out) && !is_writable(dirname(
$out)) || (file_exists(
$out) && !is_writable(
$out)))) {
 
  487        $in_file = gzopen(
$in, 
"rb");
 
  488        $out_file = fopen(
$out, 
"wb");
 
  490        while (!gzeof($in_file)) {
 
  491            $buffer = gzread($in_file, 4096);
 
  492            fwrite($out_file, $buffer, 4096);
 
  509        $finfo = 
new finfo(FILEINFO_MIME);
 
  511        return $finfo->buffer($content);
 
  522        if (!file_exists($a_file) or !is_readable($a_file)) {
 
  550        $setting = 
$DIC->settings();
 
  556        foreach (explode(
",", $setting->get(
"suffix_repl_additional")) as $custom_black) {
 
  557            $custom_black = trim(strtolower($custom_black));
 
  558            if ((
$key = array_search($custom_black, $whitelist)) !== 
false) {
 
  559                unset($whitelist[
$key]);
 
  564        foreach (explode(
",", $setting->get(
"suffix_custom_white_list")) as $custom_white) {
 
  565            $custom_white = trim(strtolower($custom_white));
 
  566            if (!in_array($custom_white, $whitelist)) {
 
  567                $whitelist[] = $custom_white;
 
  839        if (!self::hasValidExtension($a_filename)) {
 
  840            $pi = pathinfo($a_filename);
 
  842            $basename = str_replace(
".", 
"", $pi[
"basename"]);
 
  843            if (trim($basename) == 
"") {
 
  844                include_once(
"./Services/Utilities/classes/class.ilFileUtilsException.php");
 
  848            if ($pi[
"dirname"] != 
"" && ($pi[
"dirname"] != 
"." || substr($a_filename, 0, 2) == 
"./")) {
 
  849                $a_filename = $pi[
"dirname"] . 
"/" . $basename;
 
  851                $a_filename = $basename;
 
  866        $pi = pathinfo($a_filename);
 
  868        return (in_array(strtolower($pi[
"extension"]), self::getValidExtensions()));
 
  881    public static function rename($a_source, $a_target)
 
  883        $pi = pathinfo($a_target);
 
  884        if (!in_array(strtolower($pi[
"extension"]), self::getValidExtensions())) {
 
  885            include_once(
"./Services/Utilities/classes/class.ilFileUtilsException.php");
 
  889        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 hasValidExtension($a_filename)
static createObjects($dir, $structure, $ref_id, $containerType, $tree=null, $access_handler=null)
Recursively scans a given directory and creates file and folder/category objects.
static getValidFilename($a_filename)
Get valid filename.
static createContainer($name, $ref_id, $containerType, $tree=null, $access_handler=null)
Creates and inserts container object (folder/category) into tree.
static processZipFile($a_directory, $a_file, $structure, $ref_id=null, $containerType=null, $tree=null, $access_handler=null)
unzips in given directory and processes uploaded zip for use as single files
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 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($a_file, $overwrite=false, $a_flat=false)
unzip file
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled