35 include_once
'Services/Utilities/classes/class.ilFileUtilsException.php';
55 function processZipFile ($a_directory, $a_file, $structure,
$ref_id = null, $containerType = null, $tree = null, $access_handler = null) {
58 include_once(
"Services/Utilities/classes/class.ilUtil.php");
60 self::$new_files = array();
62 $pathinfo = pathinfo($a_file);
63 $file = $pathinfo[
"basename"];
68 move_uploaded_file($a_file, $a_directory .
"/" .
$file);
70 unlink ($a_directory .
"/" . $file);
77 if (empty($filearray)) {
83 foreach ($filearray[
"file"] as $key => $value)
86 if(substr($value, 0, 1) ==
"." || stristr($filearray[
"path"][$key],
"/__MACOSX/"))
88 unlink($filearray[
"path"][$key].$value);
89 unset($filearray[
"path"][$key]);
90 unset($filearray[
"file"][$key]);
98 unlink($filearray[path][$key]);
115 foreach (array_count_values($filearray[
"file"]) as $key => $value)
124 if (isset($doublettes))
126 throw new ilFileUtilsException($lng->txt(
"exc_upload_error") .
"<br />" . $lng->txt(
"zip_structure_error") . $doublettes ,
133 $mac_dir = $a_directory.
"/__MACOSX";
134 if(file_exists($mac_dir))
160 $dirlist = opendir($dir);
161 while (
false !== (
$file = readdir ($dirlist)))
163 if (!is_file($dir .
"/" .
$file) && !is_dir($dir .
"/" . $file))
168 if ($file !=
'.' && $file !=
'..')
170 $newpath = $dir.
'/'.
$file;
171 $level = explode(
'/',$newpath);
172 if (is_dir($newpath))
178 $arr[
"path"][] = $dir .
"/";
179 $arr[
"file"][] = end($level);
202 $dirlist = opendir($dir);
204 while (
false !== (
$file = readdir ($dirlist)))
206 if (!is_file($dir .
"/" .
$file) && !is_dir($dir .
"/" . $file))
210 if ($file !=
'.' && $file !=
'..')
212 $newpath = $dir.
'/'.
$file;
213 $level = explode(
'/',$newpath);
214 if (is_dir($newpath))
248 switch($containerType)
251 include_once(
"./Modules/Category/classes/class.ilObjCategory.php");
253 $newObj->setType(
"cat");
257 include_once(
"./Modules/Folder/classes/class.ilObjFolder.php");
259 $newObj->setType(
"fold");
262 case "WorkspaceFolder":
263 include_once(
"./Modules/WorkspaceFolder/classes/class.ilObjWorkspaceFolder.php");
268 $newObj->setTitle($name);
274 $newObj->createReference();
276 $newObj->setPermissions(
$ref_id);
278 if ($newObj->getType() ==
"cat")
281 $newObj->addTranslation($name,
"", $lng->getLangKey(), $lng->getLangKey());
284 self::$new_files[
$ref_id][] = $newObj;
286 return $newObj->getRefId();
291 $node_id = $tree->insertObject(
$ref_id, $newObj->getId());
292 $access_handler->setPermissions(
$ref_id, $node_id);
313 $permission = $rbacsystem->checkAccess(
"create",
$ref_id,
"file");
317 $permission = $access_handler->checkAccess(
"create",
"",
$ref_id,
"file");
322 include_once(
"./Modules/File/classes/class.ilObjFile.php");
324 $fileObj->setType($this->type);
329 include_once(
"./Services/MediaObjects/classes/class.ilObjMediaObject.php");
337 $fileObj->createReference();
339 $fileObj->setPermissions(
$ref_id);
341 self::$new_files[
$ref_id][] = $fileObj;
345 $node_id = $tree->insertObject(
$ref_id, $fileObj->getId());
346 $access_handler->setPermissions(
$ref_id, $node_id);
350 $fileObj->createDirectory();
354 $this->ilErr->raiseError($this->lng->txt(
"permission_denied"),$this->ilErr->MESSAGE);
374 return (preg_match(
'%^(?:
375 [\x09\x0A\x0D\x20-\x7E] # ASCII
376 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
377 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
378 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
379 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
380 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
381 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
382 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
383 )*$%xs', $string))? $string :
utf8_encode($string);
394 $fh = fopen($filein,
'rb');
395 $fh2= fopen($fileout,
'wb');
396 stream_filter_append($fh2,
'convert.base64-decode');
400 if ($chunk ===
false)
402 fwrite ($fh2, $chunk);
416 $fh = fopen($filein,
'rb');
417 $fh2= fopen($fileout,
'wb');
418 stream_filter_append($fh2,
'convert.base64-encode');
421 $chunk = fgets($fh,76);
422 if ($chunk ===
false)
426 fwrite ($fh2, $chunk);
443 if (!file_exists (
$in) || !is_readable (
$in))
445 if ((!file_exists (
$out) && !is_writable (dirname (
$out)) || (file_exists(
$out) && !is_writable(
$out)) ))
448 $in_file = fopen (
$in,
"rb");
449 if (!$out_file = gzopen (
$out,
"wb".$param)) {
453 while (!feof ($in_file)) {
454 $buffer = fgets ($in_file, 4096);
455 gzwrite ($out_file, $buffer, 4096);
474 if (!file_exists (
$in) || !is_readable (
$in))
476 if ((!file_exists (
$out) && !is_writable (dirname (
$out)) || (file_exists(
$out) && !is_writable(
$out)) ))
479 $in_file = gzopen (
$in,
"rb");
480 $out_file = fopen (
$out,
"wb");
482 while (!gzeof ($in_file)) {
483 $buffer = gzread ($in_file, 4096);
484 fwrite ($out_file, $buffer, 4096);
498 if(!file_exists($a_file) or !is_readable($a_file))
503 if(class_exists(
'finfo'))
505 $finfo =
new finfo(FILEINFO_MIME);
506 return $finfo->buffer(file_get_contents($a_file));
508 if(function_exists(
'mime_content_type'))
510 return mime_content_type($a_file);
512 return 'application/octet-stream';