ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilFileUtils.php
Go to the documentation of this file.
1<?php
2/*
3+-----------------------------------------------------------------------------+
4| ILIAS open source |
5+-----------------------------------------------------------------------------+
6| Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7| |
8| This program is free software; you can redistribute it and/or |
9| modify it under the terms of the GNU General Public License |
10| as published by the Free Software Foundation; either version 2 |
11| of the License, or (at your option) any later version. |
12| |
13| This program is distributed in the hope that it will be useful, |
14| but WITHOUT ANY WARRANTY; without even the implied warranty of |
15| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16| GNU General Public License for more details. |
17| |
18| You should have received a copy of the GNU General Public License |
19| along with this program; if not, write to the Free Software |
20| Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21+-----------------------------------------------------------------------------+
22*/
23
35include_once 'Services/Utilities/classes/class.ilFileUtilsException.php';
36
37
39{
40 protected static $new_files = array();
41
55 function processZipFile ($a_directory, $a_file, $structure, $ref_id = null, $containerType = null, $tree = null, $access_handler = null) {
56
57 global $lng;
58 include_once("Services/Utilities/classes/class.ilUtil.php");
59
60 self::$new_files = array();
61
62 $pathinfo = pathinfo($a_file);
63 $file = $pathinfo["basename"];
64
65 // see 22727
66 if ($pathinfo["extension"] == "")
67 {
68 $file.= ".zip";
69 }
70
71 // Copy zip-file to new directory, unzip and remove it
72 // TODO: check archive for broken file
73 //copy ($a_file, $a_directory . "/" . $file);
74 ilUtil::moveUploadedFile($a_file, $file, $a_directory . "/" . $file);
75 ilUtil::unzip($a_directory . "/" . $file);
76 unlink ($a_directory . "/" . $file);
77//echo "-".$a_directory . "/" . $file."-";
78 // Stores filename and paths into $filearray to check for viruses
79 // Checks if filenames can be read, else -> throw exception and leave
80 ilFileUtils::recursive_dirscan($a_directory, $filearray);
81
82 // if there are no files unziped (->broken file!)
83 if (empty($filearray)) {
84 throw new ilFileUtilsException($lng->txt("archive_broken"), ilFileUtilsException::$BROKEN_FILE);
85 break;
86 }
87
88 // virus handling
89 foreach ($filearray["file"] as $key => $value)
90 {
91 // remove "invisible" files
92 if(substr($value, 0, 1) == "." || stristr($filearray["path"][$key], "/__MACOSX/"))
93 {
94 unlink($filearray["path"][$key].$value);
95 unset($filearray["path"][$key]);
96 unset($filearray["file"][$key]);
97 continue;
98 }
99
100 $vir = ilUtil::virusHandling($filearray["path"][$key], $value);
101 if (!$vir[0])
102 {
103 // Unlink file and throw exception
104 unlink($filearray[path][$key]);
105 throw new ilFileUtilsException($lng->txt("file_is_infected")."<br />".$vir[1], ilFileUtilsException::$INFECTED_FILE);
106 break;
107 }
108 else
109 {
110 if ($vir[1] != "")
111 {
113 break;
114 }
115 }
116 }
117
118 // If archive is to be used "flat"
119 if (!$structure)
120 {
121 foreach (array_count_values($filearray["file"]) as $key => $value)
122 {
123 // Archive contains same filenames in different directories
124 if ($value != "1")
125 {
126 $doublettes .= " '" . ilFileUtils::utf8_encode($key) . "'";
127
128 }
129 }
130 if (isset($doublettes))
131 {
132 throw new ilFileUtilsException($lng->txt("exc_upload_error") . "<br />" . $lng->txt("zip_structure_error") . $doublettes ,
134 break;
135 }
136 }
137 else
138 {
139 $mac_dir = $a_directory."/__MACOSX";
140 if(file_exists($mac_dir))
141 {
142 ilUtil::delDir($mac_dir);
143 }
144 }
145
146 // Everything fine since we got here; so we can store files and folders into the system (if ref_id is given)
147 if ($ref_id != null)
148 {
149 ilFileUtils::createObjects ($a_directory, $structure, $ref_id, $containerType, $tree, $access_handler);
150 }
151
152 }
153
162 function recursive_dirscan($dir, &$arr)
163 {
164 global $lng;
165
166 $dirlist = opendir($dir);
167 while (false !== ($file = readdir ($dirlist)))
168 {
169 if (!is_file($dir . "/" . $file) && !is_dir($dir . "/" . $file))
170 {
171 throw new ilFileUtilsException($lng->txt("filenames_not_supported"), ilFileUtilsException::$BROKEN_FILE);
172 }
173
174 if ($file != '.' && $file != '..')
175 {
176 $newpath = $dir.'/'.$file;
177 $level = explode('/',$newpath);
178 if (is_dir($newpath))
179 {
180 ilFileUtils::recursive_dirscan($newpath, $arr);
181 }
182 else
183 {
184 $arr["path"][] = $dir . "/";
185 $arr["file"][] = end($level);
186 }
187 }
188 }
189 closedir($dirlist);
190 }
191
192
206 function createObjects($dir, $structure, $ref_id, $containerType, $tree = null, $access_handler = null)
207 {
208 $dirlist = opendir($dir);
209
210 while (false !== ($file = readdir ($dirlist)))
211 {
212 if (!is_file($dir . "/" . $file) && !is_dir($dir . "/" . $file))
213 {
214 throw new ilFileUtilsException($lng->txt("filenames_not_supported") , ilFileUtilsException::$BROKEN_FILE);
215 }
216 if ($file != '.' && $file != '..')
217 {
218 $newpath = $dir.'/'.$file;
219 $level = explode('/',$newpath);
220 if (is_dir($newpath))
221 {
222 if ($structure)
223 {
224 $new_ref_id = ilFileUtils::createContainer(ilFileUtils::utf8_encode($file), $ref_id, $containerType, $tree, $access_handler);
225 ilFileUtils::createObjects($newpath, $structure, $new_ref_id, $containerType, $tree, $access_handler);
226 }
227 else
228 {
229 ilFileUtils::createObjects($newpath, $structure, $ref_id, $containerType, $tree, $access_handler);
230 }
231 }
232 else
233 {
234 ilFileUtils::createFile (end($level), $dir, $ref_id, $tree, $access_handler);
235 }
236 }
237 }
238 closedir($dirlist);
239 }
240
241
252 function createContainer($name, $ref_id, $containerType, $tree = null, $access_handler = null)
253 {
254 switch($containerType)
255 {
256 case "Category":
257 include_once("./Modules/Category/classes/class.ilObjCategory.php");
258 $newObj = new ilObjCategory();
259 $newObj->setType("cat");
260 break;
261
262 case "Folder":
263 include_once("./Modules/Folder/classes/class.ilObjFolder.php");
264 $newObj = new ilObjFolder();
265 $newObj->setType("fold");
266 break;
267
268 case "WorkspaceFolder":
269 include_once("./Modules/WorkspaceFolder/classes/class.ilObjWorkspaceFolder.php");
270 $newObj = new ilObjWorkspaceFolder();
271 break;
272 }
273
274 $newObj->setTitle($name);
275 $newObj->create();
276
277 // repository
278 if(!$access_handler)
279 {
280 $newObj->createReference();
281 $newObj->putInTree($ref_id);
282 $newObj->setPermissions($ref_id);
283
284 if ($newObj->getType() == "cat")
285 {
286 global $lng;
287 $newObj->addTranslation($name,"", $lng->getLangKey(), $lng->getLangKey());
288 }
289
290 self::$new_files[$ref_id][] = $newObj;
291
292 return $newObj->getRefId();
293 }
294 // workspace
295 else
296 {
297 $node_id = $tree->insertObject($ref_id, $newObj->getId());
298 $access_handler->setPermissions($ref_id, $node_id);
299
300 return $node_id;
301 }
302 }
303
313 public static function createFile ($filename, $path, $ref_id, $tree = null, $access_handler = null)
314 {
315 global $rbacsystem, $lng, $ilErr;
316
317 if(!$access_handler)
318 {
319 $permission = $rbacsystem->checkAccess("create", $ref_id, "file");
320 }
321 else
322 {
323 $permission = $access_handler->checkAccess("create", "", $ref_id, "file");
324 }
325 if ($permission) {
326
327 // create and insert file in grp_tree
328 include_once("./Modules/File/classes/class.ilObjFile.php");
329 $fileObj = new ilObjFile();
330 $fileObj->setType('file');
333
334 // better use this, mime_content_type is deprecated
335 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
336 $fileObj->setFileType(ilObjMediaObject::getMimeType($path. "/" . $filename));
337 $fileObj->setFileSize(filesize($path. "/" . $filename));
338 $fileObj->create();
339
340 // repository
341 if(!$access_handler)
342 {
343 $fileObj->createReference();
344 $fileObj->putInTree($ref_id);
345 $fileObj->setPermissions($ref_id);
346
347 self::$new_files[$ref_id][] = $fileObj;
348 }
349 else
350 {
351 $node_id = $tree->insertObject($ref_id, $fileObj->getId());
352 $access_handler->setPermissions($ref_id, $node_id);
353 }
354
355 // upload file to filesystem
356 $fileObj->createDirectory();
357 $fileObj->storeUnzipedFile($path. "/" . $filename,ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename)));
358 }
359 else {
360 $ilErr->raiseError($lng->txt("permission_denied"),$ilErr->MESSAGE);
361 }
362 }
363
364 public static function getNewObjects()
365 {
366 return self::$new_files;
367 }
368
377 function utf8_encode($string) {
378
379 // From http://w3.org/International/questions/qa-forms-utf-8.html
380 return (preg_match('%^(?:
381 [\x09\x0A\x0D\x20-\x7E] # ASCII
382 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
383 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
384 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
385 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
386 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
387 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
388 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
389 )*$%xs', $string))? $string : utf8_encode($string);
390 }
391
392
398 function fastBase64Decode ($filein, $fileout)
399 {
400 $fh = fopen($filein, 'rb');
401 $fh2= fopen($fileout, 'wb');
402 stream_filter_append($fh2, 'convert.base64-decode');
403
404 while (!feof($fh)){
405 $chunk = fgets($fh);
406 if ($chunk === false)
407 break;
408 fwrite ($fh2, $chunk);
409 }
410 fclose ($fh);
411 fclose ($fh2);
412 return true;
413 }
414
420 function fastBase64Encode ($filein, $fileout)
421 {
422 $fh = fopen($filein, 'rb');
423 $fh2= fopen($fileout, 'wb');
424 stream_filter_append($fh2, 'convert.base64-encode');
425
426 while (feof ($fh)) {
427 $chunk = fgets($fh,76);
428 if ($chunk === false)
429 {
430 break;
431 }
432 fwrite ($fh2, $chunk);
433 }
434 fclose ($fh);
435 fclose ($fh2);
436 }
437
447 function fastGZip ($in, $out, $level="9")
448 {
449 if (!file_exists ($in) || !is_readable ($in))
450 return false;
451 if ((!file_exists ($out) && !is_writable (dirname ($out)) || (file_exists($out) && !is_writable($out)) ))
452 return false;
453
454 $in_file = fopen ($in, "rb");
455 if (!$out_file = gzopen ($out, "wb".$param)) {
456 return false;
457 }
458
459 while (!feof ($in_file)) {
460 $buffer = fgets ($in_file, 4096);
461 gzwrite ($out_file, $buffer, 4096);
462 }
463
464 fclose ($in_file);
465 gzclose ($out_file);
466
467 return true;
468 }
469
478 function fastGunzip ($in, $out)
479 {
480 if (!file_exists ($in) || !is_readable ($in))
481 return false;
482 if ((!file_exists ($out) && !is_writable (dirname ($out)) || (file_exists($out) && !is_writable($out)) ))
483 return false;
484
485 $in_file = gzopen ($in, "rb");
486 $out_file = fopen ($out, "wb");
487
488 while (!gzeof ($in_file)) {
489 $buffer = gzread ($in_file, 4096);
490 fwrite ($out_file, $buffer, 4096);
491 }
492
493 gzclose ($in_file);
494 fclose ($out_file);
495
496 return true;
497 }
498
503 public static function lookupContentMimeType($content)
504 {
505 $finfo = new finfo(FILEINFO_MIME);
506 return $finfo->buffer($content);
507 }
508
513 public static function lookupFileMimeType($a_file)
514 {
515 if(!file_exists($a_file) or !is_readable($a_file))
516 {
517 return false;
518 }
519
520 return self::lookupContentMimeType(file_get_contents($a_file));
521 }
522
527 public static function _lookupMimeType($a_file)
528 {
529 return self::lookupFileMimeType($a_file);
530 }
531
532
536 public static function getValidExtensions() {
537 global $ilSetting;
538
539 // default white list
541
542 // remove custom black list values
543 foreach (explode(",", $ilSetting->get("suffix_repl_additional")) as $custom_black) {
544 $custom_black = trim(strtolower($custom_black));
545 if (($key = array_search($custom_black, $whitelist)) !== false) {
546 unset($whitelist[$key]);
547 }
548 }
549
550 // add custom white list values
551 foreach (explode(",", $ilSetting->get("suffix_custom_white_list")) as $custom_white) {
552 $custom_white = trim(strtolower($custom_white));
553 if (!in_array($custom_white, $whitelist)) {
554 $whitelist[] = $custom_white;
555 }
556 }
557
558 return $whitelist;
559 }
560
565 public static function getDefaultValidExtensionWhiteList()
566 {
567 return array(
568 '3gp', // VIDEO__3_GPP
569 'ai', // APPLICATION__POSTSCRIPT
570 'aif', // AUDIO__AIFF
571 'aifc', // AUDIO__AIFF
572 'aiff', // AUDIO__AIFF
573 'au', // AUDIO__BASIC
574 'arw', // IMAGE__X_SONY_ARW
575 'avi', // AUDIO__BASIC
576 'backup', // scorm wbts
577 'bak', // scorm wbts
578 'bpmn', // bpmn
579 'bpmn2', // bpmn2
580 'bmp', // IMAGE__BMP
581 'bib', // bibtex
582 'bibtex', // bibtex
583 'bz', // APPLICATION__X_BZIP
584 'bz2', // APPLICATION__X_BZIP2
585 'c', // TEXT__PLAIN
586 'c++', // TEXT__PLAIN
587 'cc', // TEXT__PLAIN
588 'cct', // scorm wbts
589 'cer', // APPLICATION__X_X509_CA_CERT
590 'class', // APPLICATION__X_JAVA_CLASS
591 'conf', // TEXT__PLAIN
592 'cpp', // TEXT__X_C
593 'crt', // APPLICATION__X_X509_CA_CERT
594 'crs', // scorm wbts
595 'crw', // IMAGE__X_CANON_CRW
596 'cr2', // IMAGE__X_CANON_CR2
597 'css', // TEXT__CSS
598 'cst', // scorm wbts
599 'csv',
600 'cur', // scorm wbts
601 'db', // scorm wbts
602 'dcr', // scorm wbts
603 'des', // scorm wbts
604 'dng', // IMAGE__X_ADOBE_DNG
605 'doc', // APPLICATION__MSWORD,
606 'docx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_DOCUMENT,
607 'dot', // APPLICATION__MSWORD,
608 'dotx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_TEMPLATE,
609 'dtd',
610 'dvi', // APPLICATION__X_DVI,
611 'el', // TEXT__X_SCRIPT_ELISP,
612 'eps', // APPLICATION__POSTSCRIPT,
613 'epub', // APPLICATION__EPUB,
614 'f', // TEXT__X_FORTRAN,
615 'f77', // TEXT__X_FORTRAN,
616 'f90', // TEXT__X_FORTRAN,
617 'flv', // VIDEO__X_FLV,
618 'for', // TEXT__X_FORTRAN,
619 'g3', // IMAGE__G3FAX,
620 'gif', // IMAGE__GIF,
621 'gl', // VIDEO__GL,
622 'gan',
623 'gsd', // AUDIO__X_GSM,
624 'gsm', // AUDIO__X_GSM,
625 'gtar', // APPLICATION__X_GTAR,
626 'gz', // APPLICATION__X_GZIP,
627 'gzip', // APPLICATION__X_GZIP,
628 'htm', // TEXT__HTML,
629 'html', // TEXT__HTML,
630 'htmls', // TEXT__HTML,
631 'ico', // IMAGE__X_ICON,
632 'ics', // iCalendar, TEXT__CALENDAR
633 'ini', // scorm wbts
634 'java', // TEXT__X_JAVA_SOURCE,
635 'jbf', // scorm wbts
636 'jpeg', // IMAGE__PJPEG,
637 'jpg', // IMAGE__JPEG,
638 'js', // APPLICATION__X_JAVASCRIPT,
639 'jsf', // scorm wbts
640 'jso', // scorm wbts
641 'json', // APPLICATION__JSON
642 'latex', // APPLICATION__X_LATEX,
643 'lang', // lang files
644 'less', // less
645 'log', // TEXT__PLAIN,
646 'lsp', // APPLICATION__X_LISP,
647 'ltx', // APPLICATION__X_LATEX,
648 'm1v', // VIDEO__MPEG,
649 'm2a', // AUDIO__MPEG,
650 'm2v', // VIDEO__MPEG,
651 'm3u', // AUDIO__X_MPEQURL,
652 'm4a', // AUDIO__MP4,
653 'm4v', // VIDEO__MP4,
654 'markdown', // TEXT__MARKDOWN,
655 'm', // MATLAB
656 'mat', // MATLAB
657 'md', // TEXT__MARKDOWN,
658 'mdown', // TEXT__MARKDOWN,
659 'mid', // AUDIO__MIDI,
660 'min', // scorm articulate?
661 'midi', // AUDIO__MIDI,
662 'mobi', // APPLICATION__X_MOBI,
663 'mod', // AUDIO__MOD,
664 'mov', // VIDEO__QUICKTIME,
665 'movie', // VIDEO__X_SGI_MOVIE,
666 'mp2', // AUDIO__X_MPEG,
667 'mp3', // AUDIO__X_MPEG3,
668 'mp4', // VIDEO__MP4,
669 'mpa', // AUDIO__MPEG,
670 'mpeg', // VIDEO__MPEG,
671 'mpg', // AUDIO__MPEG,
672 'mph',
673 'mpga', // AUDIO__MPEG,
674 'mpp', // APPLICATION__VND_MS_PROJECT,
675 'mpt', // APPLICATION__X_PROJECT,
676 'mpv', // APPLICATION__X_PROJECT,
677 'mpx', // APPLICATION__X_PROJECT,
678 'mv', // VIDEO__X_SGI_MOVIE,
679 'mw',
680 'mv4', // VIDEO__MP4,
681 'nef', // IMAGE__X_NIKON_NEF,
682 'nif', // IMAGE__X_NIFF,
683 'niff', // IMAGE__X_NIFF,
684 'odt', // Open document text,
685 'ods', // Open document spreadsheet,
686 'odp', // Open document presentation,
687 'odg', // Open document graphics,
688 'odf', // Open document formula,
689 'oga', // AUDIO__OGG,
690 'ogg', // AUDIO__OGG,
691 'ogv', // VIDEO__OGG,
692 'old', // no real file extension, but used in mail/forum components,
693 'p', // TEXT__X_PASCAL,
694 'pas', // TEXT__PASCAL,
695 'pbm', // IMAGE__X_PORTABLE_BITMAP,
696 'pcl', // APPLICATION__VND_HP_PCL,
697 'pct', // IMAGE__X_PICT,
698 'pcx', // IMAGE__X_PCX,
699 'pdf', // APPLICATION__PDF,
700 'pgm', // IMAGE__X_PORTABLE_GRAYMAP,
701 'pic', // IMAGE__PICT,
702 'pict', // IMAGE__PICT,
703 'png', // IMAGE__PNG,
704 'pov', // MODEL__X_POV,
705 'project', // scorm wbts
706 'properties', // scorm wbts
707 'ppa', // APPLICATION__VND_MS_POWERPOINT,
708 'ppm', // IMAGE__X_PORTABLE_PIXMAP,
709 'pps', // APPLICATION__VND_MS_POWERPOINT,
710 'ppsx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_SLIDESHOW,
711 'ppt', // APPLICATION__POWERPOINT,
712 'pptx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_PRESENTATION,
713 'ppz', // APPLICATION__MSPOWERPOINT,
714 'ps', // APPLICATION__POSTSCRIPT,
715 'psd', // scorm wbts
716 'pwz', // APPLICATION__VND_MS_POWERPOINT,
717 'qt', // VIDEO__QUICKTIME,
718 'qtc', // VIDEO__X_QTC,
719 'qti', // IMAGE__X_QUICKTIME,
720 'qtif', // IMAGE__X_QUICKTIME,
721 'ra', // AUDIO__X_PN_REALAUDIO,
722 'ram', // AUDIO__X_PN_REALAUDIO,
723 'rast', // IMAGE__CMU_RASTER,
724 'rexx', // TEXT__X_SCRIPT_REXX,
725 'ris', // ris
726 'rf', // IMAGE__VND_RN_REALFLASH,
727 'rgb', // IMAGE__X_RGB,
728 'rm', // APPLICATION__VND_RN_REALMEDIA,
729 'rmi', // AUDIO__MID,
730 'rmm', // AUDIO__X_PN_REALAUDIO,
731 'rmp', // AUDIO__X_PN_REALAUDIO,
732 'rt', // TEXT__RICHTEXT,
733 'rtf', // TEXT__RICHTEXT,
734 'rtx', // TEXT__RICHTEXT,
735 'rv', // VIDEO__VND_RN_REALVIDEO,
736 's', // TEXT__X_ASM,
737 'sav', // SPSS
738 'sec', //
739 's3m', // AUDIO__S3M,
740 'sdml', // TEXT__PLAIN,
741 'sgm', // TEXT__SGML,
742 'sgml', // TEXT__SGML
743 'smi', // APPLICATION__SMIL,
744 'smil', // APPLICATION__SMIL,
745 'svg', // IMAGE__SVG_XML,
746 'swa', // scorm wbts
747 'swf', // APPLICATION__X_SHOCKWAVE_FLASH,
748 'swz', // scorm wbts
749 'tex', // APPLICATION__X_TEX,
750 'texi', // APPLICATION__X_TEXINFO,
751 'texinfo', // APPLICATION__X_TEXINFO,
752 'text', // TEXT__PLAIN,
753 'tgz', // APPLICATION__X_COMPRESSED,
754 'tif', // IMAGE__TIFF,
755 'tiff', // IMAGE__TIFF,
756 'ttf', // scorm wbts
757 'txt', // TEXT__PLAIN,
758 'tmp',
759 'uvproj',
760 'vimeo', // VIDEO__VIMEO,
761 'viv', // VIDEO__VIMEO,
762 'vivo', // VIDEO__VIVO,
763 'vrml', // APPLICATION__X_VRML,
764 'wav', // wav
765 'webm', // VIDEO__WEBM,
766 'wmv', // VIDEO__X_MS_WMV,
767 'wmx', // VIDEO__X_MS_WMX,
768 'wmz', // VIDEO__X_MS_WMZ,
769 'woff', // web open font format,
770 'xhtml', // APPLICATION__XHTML_XML,
771 'xif', // IMAGE__VND_XIFF,
772 'xls', // APPLICATION__EXCEL,
773 'xlsx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET,
774 'xmind',
775 'xml', // self::TEXT__XML,
776 'xsl', // APPLICATION__XML,
777 'xsd', // scorm
778 'zip' // APPLICATION__ZIP
779 );
780 }
781
789 public static function getValidFilename($a_filename)
790 {
791 $pi = pathinfo($a_filename);
792 if (!in_array(strtolower($pi["extension"]), self::getValidExtensions())) {
793
794 // if extension is not in white list, remove all "." and add ".sec" extension
795 $basename = str_replace(".", "", $pi["basename"]);
796 if (trim($basename) == "")
797 {
798 include_once("./Services/Utilities/classes/class.ilFileUtilsException.php");
799 throw new ilFileUtilsException("Invalid upload filename.");
800 }
801 $basename.= ".sec";
802 if ($pi["dirname"] != "" && ($pi["dirname"] != "." || substr($a_filename, 0, 2) == "./"))
803 {
804 $a_filename = $pi["dirname"]."/".$basename;
805 }
806 else
807 {
808 $a_filename = $basename;
809 }
810 }
811 return $a_filename;
812 }
813
814
823 public static function rename($a_source, $a_target)
824 {
825 $pi = pathinfo($a_target);
826 if (!in_array(strtolower($pi["extension"]), self::getValidExtensions()))
827 {
828 include_once("./Services/Utilities/classes/class.ilFileUtilsException.php");
829 throw new ilFileUtilsException("Invalid target file ".$pi["basename"].".");
830 }
831
832 return rename($a_source, $a_target);
833 }
834
835
836} // END class.ilFileUtils
837
838
839?>
print $file
$filename
Definition: buildRTE.php:89
Class to report exception.
fileUtils class various functions for zip-archive handling
fastGunzip($in, $out)
fast uncompressing the file with the zlib-extension without memory consumption
createContainer($name, $ref_id, $containerType, $tree=null, $access_handler=null)
Creates and inserts container object (folder/category) into tree.
static getValidFilename($a_filename)
Get valid filename.
static getNewObjects()
static getDefaultValidExtensionWhiteList()
Valid extensions.
static getValidExtensions()
createObjects($dir, $structure, $ref_id, $containerType, $tree=null, $access_handler=null)
Recursively scans a given directory and creates file and folder/category objects.
fastBase64Encode($filein, $fileout)
static lookupContentMimeType($content)
utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
static _lookupMimeType($a_file)
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
fastGZip($in, $out, $level="9")
fast compressing the file with the zlib-extension without memory consumption
static createFile($filename, $path, $ref_id, $tree=null, $access_handler=null)
Creates and inserts file object into tree.
recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static lookupFileMimeType($a_file)
fastBase64Decode($filein, $fileout)
static rename($a_source, $a_target)
Rename a file.
Class ilObjCategory.
Class ilObjFile.
Class ilObjFolder.
static getMimeType($a_file, $a_external=false)
get mime type for file
Class ilObjWorkspaceFolder.
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($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
global $lng
Definition: privfeed.php:40
global $ilSetting
Definition: privfeed.php:40
$ref_id
Definition: sahs_server.php:39
$path
Definition: index.php:22