35 include_once
'Services/Utilities/classes/class.ilFileUtilsException.php';
55 public static function processZipFile ($a_directory, $a_file, $structure,
$ref_id = null, $containerType = null, $tree = null, $access_handler = null) {
59 self::$new_files =
array();
61 $pathinfo = pathinfo($a_file);
62 $file = $pathinfo[
"basename"];
65 if ($pathinfo[
"extension"] ==
"")
75 unlink ($a_directory .
"/" . $file);
82 if (empty($filearray)) {
87 foreach ($filearray[
"file"] as $key => $value)
90 if(substr($value, 0, 1) ==
"." || stristr($filearray[
"path"][$key],
"/__MACOSX/"))
92 unlink($filearray[
"path"][$key].$value);
93 unset($filearray[
"path"][$key]);
94 unset($filearray[
"file"][$key]);
102 unlink($filearray[path][$key]);
119 foreach (array_count_values($filearray[
"file"]) as $key => $value)
128 if (isset($doublettes))
130 throw new ilFileUtilsException($lng->txt(
"exc_upload_error") .
"<br />" . $lng->txt(
"zip_structure_error") . $doublettes ,
136 $mac_dir = $a_directory.
"/__MACOSX";
137 if(file_exists($mac_dir))
163 $dirlist = opendir($dir);
164 while (
false !== (
$file = readdir ($dirlist)))
166 if (!is_file($dir .
"/" .
$file) && !is_dir($dir .
"/" . $file))
171 if ($file !=
'.' && $file !=
'..')
173 $newpath = $dir.
'/'.
$file;
174 $level = explode(
'/',$newpath);
175 if (is_dir($newpath))
181 $arr[
"path"][] = $dir .
"/";
182 $arr[
"file"][] = end($level);
203 public static function createObjects($dir, $structure,
$ref_id, $containerType, $tree = null, $access_handler = null)
205 $dirlist = opendir($dir);
207 while (
false !== (
$file = readdir ($dirlist)))
209 if (!is_file($dir .
"/" .
$file) && !is_dir($dir .
"/" . $file))
213 if ($file !=
'.' && $file !=
'..')
215 $newpath = $dir.
'/'.
$file;
216 $level = explode(
'/',$newpath);
217 if (is_dir($newpath))
251 switch($containerType)
254 include_once(
"./Modules/Category/classes/class.ilObjCategory.php");
256 $newObj->setType(
"cat");
260 include_once(
"./Modules/Folder/classes/class.ilObjFolder.php");
262 $newObj->setType(
"fold");
265 case "WorkspaceFolder":
266 include_once(
"./Modules/WorkspaceFolder/classes/class.ilObjWorkspaceFolder.php");
271 $newObj->setTitle($name);
277 $newObj->createReference();
279 $newObj->setPermissions(
$ref_id);
281 if ($newObj->getType() ==
"cat")
284 $newObj->addTranslation($name,
"", $lng->getLangKey(), $lng->getLangKey());
287 self::$new_files[
$ref_id][] = $newObj;
289 return $newObj->getRefId();
294 $node_id = $tree->insertObject(
$ref_id, $newObj->getId());
295 $access_handler->setPermissions(
$ref_id, $node_id);
316 $permission = $rbacsystem->checkAccess(
"create",
$ref_id,
"file");
320 $permission = $access_handler->checkAccess(
"create",
"",
$ref_id,
"file");
325 include_once(
"./Modules/File/classes/class.ilObjFile.php");
327 $fileObj->setType(
'file');
332 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
340 $fileObj->createReference();
342 $fileObj->setPermissions(
$ref_id);
344 self::$new_files[
$ref_id][] = $fileObj;
348 $node_id = $tree->insertObject(
$ref_id, $fileObj->getId());
349 $access_handler->setPermissions(
$ref_id, $node_id);
353 $fileObj->createDirectory();
357 $ilErr->raiseError($lng->txt(
"permission_denied"),$ilErr->MESSAGE);
363 return self::$new_files;
377 return (preg_match(
'%^(?: 378 [\x09\x0A\x0D\x20-\x7E] # ASCII 379 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte 380 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs 381 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte 382 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates 383 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 384 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 385 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 386 )*$%xs', $string))? $string :
utf8_encode($string);
397 $fh = fopen($filein,
'rb');
398 $fh2= fopen($fileout,
'wb');
399 stream_filter_append($fh2,
'convert.base64-decode');
403 if ($chunk ===
false)
405 fwrite ($fh2, $chunk);
419 $fh = fopen($filein,
'rb');
420 $fh2= fopen($fileout,
'wb');
421 stream_filter_append($fh2,
'convert.base64-encode');
424 $chunk = fgets(
$fh,76);
425 if ($chunk ===
false)
429 fwrite ($fh2, $chunk);
446 if (!file_exists (
$in) || !is_readable (
$in))
448 if ((!file_exists (
$out) && !is_writable (dirname (
$out)) || (file_exists(
$out) && !is_writable(
$out)) ))
451 $in_file = fopen (
$in,
"rb");
452 if (!$out_file = gzopen (
$out,
"wb".$param)) {
456 while (!feof ($in_file)) {
457 $buffer = fgets ($in_file, 4096);
458 gzwrite ($out_file, $buffer, 4096);
477 if (!file_exists (
$in) || !is_readable (
$in))
479 if ((!file_exists (
$out) && !is_writable (dirname (
$out)) || (file_exists(
$out) && !is_writable(
$out)) ))
482 $in_file = gzopen (
$in,
"rb");
483 $out_file = fopen (
$out,
"wb");
485 while (!gzeof ($in_file)) {
486 $buffer = gzread ($in_file, 4096);
487 fwrite ($out_file, $buffer, 4096);
502 $finfo =
new finfo(FILEINFO_MIME);
503 return $finfo->buffer($content);
512 if(!file_exists($a_file)
or !is_readable($a_file))
517 return file_get_contents($a_file);
526 return self::lookupFileMimeType($a_file);
537 $whitelist = self::getDefaultValidExtensionWhiteList();
540 foreach (explode(
",", $ilSetting->get(
"suffix_repl_additional")) as $custom_black) {
541 $custom_black = trim(strtolower($custom_black));
542 if (($key = array_search($custom_black, $whitelist)) !==
false) {
543 unset($whitelist[$key]);
548 foreach (explode(
",", $ilSetting->get(
"suffix_custom_white_list")) as $custom_white) {
549 $custom_white = trim(strtolower($custom_white));
550 if (!in_array($custom_white, $whitelist)) {
551 $whitelist[] = $custom_white;
791 $pi = pathinfo($a_filename);
792 if (!in_array(strtolower($pi[
"extension"]), self::getValidExtensions())) {
795 $basename = str_replace(
".",
"", $pi[
"basename"]);
796 if (trim($basename) ==
"")
798 include_once(
"./Services/Utilities/classes/class.ilFileUtilsException.php");
802 if ($pi[
"dirname"] !=
"" && ($pi[
"dirname"] !=
"." || substr($a_filename, 0, 2) ==
"./"))
804 $a_filename = $pi[
"dirname"].
"/".$basename;
808 $a_filename = $basename;
823 public static function rename($a_source, $a_target)
825 $pi = pathinfo($a_target);
826 if (!in_array(strtolower($pi[
"extension"]), self::getValidExtensions()))
828 include_once(
"./Services/Utilities/classes/class.ilFileUtilsException.php");
832 return rename($a_source, $a_target);
fileUtils class various functions for zip-archive handling
static createFile($filename, $path, $ref_id, $tree=null, $access_handler=null)
Creates and inserts file object into tree.
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
fastBase64Encode($filein, $fileout)
decodes base encoded file row by row to prevent memory exhaust
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
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 createContainer($name, $ref_id, $containerType, $tree=null, $access_handler=null)
Creates and inserts container object (folder/category) into tree.
static _lookupMimeType($a_file)
static rename($a_source, $a_target)
Rename a file.
static getDefaultValidExtensionWhiteList()
Valid extensions.
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static lookupFileMimeType($a_file)
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 stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static getValidExtensions()
Create styles array
The data for the language used.
if(php_sapi_name() !='cli') $in
Class ilObjWorkspaceFolder.
static utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
fastGZip($in, $out, $level="9")
fast compressing the file with the zlib-extension without memory consumption
fastBase64Decode($filein, $fileout)
decodes base encoded file row by row to prevent memory exhaust
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static lookupContentMimeType($content)
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
fastGunzip($in, $out)
fast uncompressing the file with the zlib-extension without memory consumption
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getValidFilename($a_filename)
Get valid filename.
Class to report exception.