ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
39 {
40 
44  protected static $new_files = array();
45 
46 
62  public static function processZipFile($a_directory, $a_file, $structure, $ref_id = null, $containerType = null, $tree = null, $access_handler = null)
63  {
64  global $DIC;
65 
66  $lng = $DIC->language();
67 
68  self::$new_files = array();
69 
70  $pathinfo = pathinfo($a_file);
71  $file = $pathinfo["basename"];
72 
73  // see 22727
74  if ($pathinfo["extension"] == "") {
75  $file .= ".zip";
76  }
77 
78  // Copy zip-file to new directory, unzip and remove it
79  // TODO: check archive for broken file
80  //copy ($a_file, $a_directory . "/" . $file);
81  ilUtil::moveUploadedFile($a_file, $file, $a_directory . "/" . $file);
82  ilUtil::unzip($a_directory . "/" . $file);
83  unlink($a_directory . "/" . $file);
84  //echo "-".$a_directory . "/" . $file."-";
85  // Stores filename and paths into $filearray to check for viruses
86  // Checks if filenames can be read, else -> throw exception and leave
87  ilFileUtils::recursive_dirscan($a_directory, $filearray);
88 
89  // if there are no files unziped (->broken file!)
90  if (empty($filearray)) {
91  throw new ilFileUtilsException($lng->txt("archive_broken"), ilFileUtilsException::$BROKEN_FILE);
92  }
93 
94  // virus handling
95  foreach ($filearray["file"] as $key => $value) {
96  // remove "invisible" files
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]);
101  continue;
102  }
103 
104  $vir = ilUtil::virusHandling($filearray["path"][$key], $value);
105  if (!$vir[0]) {
106  // Unlink file and throw exception
107  unlink($filearray[path][$key]);
108  throw new ilFileUtilsException($lng->txt("file_is_infected") . "<br />" . $vir[1], ilFileUtilsException::$INFECTED_FILE);
109  break;
110  } else {
111  if ($vir[1] != "") {
113  break;
114  }
115  }
116  }
117 
118  // If archive is to be used "flat"
119  if (!$structure) {
120  foreach (array_count_values($filearray["file"]) as $key => $value) {
121  // Archive contains same filenames in different directories
122  if ($value != "1") {
123  $doublettes .= " '" . ilFileUtils::utf8_encode($key) . "'";
124  }
125  }
126  if (isset($doublettes)) {
127  throw new ilFileUtilsException(
128  $lng->txt("exc_upload_error") . "<br />" . $lng->txt("zip_structure_error") . $doublettes,
130  );
131  }
132  } else {
133  $mac_dir = $a_directory . "/__MACOSX";
134  if (file_exists($mac_dir)) {
135  ilUtil::delDir($mac_dir);
136  }
137  }
138 
139  // Everything fine since we got here; so we can store files and folders into the system (if ref_id is given)
140  if ($ref_id != null) {
141  ilFileUtils::createObjects($a_directory, $structure, $ref_id, $containerType, $tree, $access_handler);
142  }
143  }
144 
145 
156  public static function recursive_dirscan($dir, &$arr)
157  {
158  global $DIC;
159 
160  $lng = $DIC->language();
161 
162  $dirlist = opendir($dir);
163  while (false !== ($file = readdir($dirlist))) {
164  if (!is_file($dir . "/" . $file) && !is_dir($dir . "/" . $file)) {
165  throw new ilFileUtilsException($lng->txt("filenames_not_supported"), ilFileUtilsException::$BROKEN_FILE);
166  }
167 
168  if ($file != '.' && $file != '..') {
169  $newpath = $dir . '/' . $file;
170  $level = explode('/', $newpath);
171  if (is_dir($newpath)) {
172  ilFileUtils::recursive_dirscan($newpath, $arr);
173  } else {
174  $arr["path"][] = $dir . "/";
175  $arr["file"][] = end($level);
176  }
177  }
178  }
179  closedir($dirlist);
180  }
181 
182 
198  public static function createObjects($dir, $structure, $ref_id, $containerType, $tree = null, $access_handler = null)
199  {
200  $dirlist = opendir($dir);
201 
202  while (false !== ($file = readdir($dirlist))) {
203  if (!is_file($dir . "/" . $file) && !is_dir($dir . "/" . $file)) {
204  throw new ilFileUtilsException($lng->txt("filenames_not_supported"), ilFileUtilsException::$BROKEN_FILE);
205  }
206  if ($file != '.' && $file != '..') {
207  $newpath = $dir . '/' . $file;
208  $level = explode('/', $newpath);
209  if (is_dir($newpath)) {
210  if ($structure) {
211  $new_ref_id = ilFileUtils::createContainer(ilFileUtils::utf8_encode($file), $ref_id, $containerType, $tree, $access_handler);
212  ilFileUtils::createObjects($newpath, $structure, $new_ref_id, $containerType, $tree, $access_handler);
213  } else {
214  ilFileUtils::createObjects($newpath, $structure, $ref_id, $containerType, $tree, $access_handler);
215  }
216  } else {
217  ilFileUtils::createFile(end($level), $dir, $ref_id, $tree, $access_handler);
218  }
219  }
220  }
221  closedir($dirlist);
222  }
223 
224 
236  public static function createContainer($name, $ref_id, $containerType, $tree = null, $access_handler = null)
237  {
238  switch ($containerType) {
239  case "Category":
240  include_once("./Modules/Category/classes/class.ilObjCategory.php");
241  $newObj = new ilObjCategory();
242  $newObj->setType("cat");
243  break;
244 
245  case "Folder":
246  include_once("./Modules/Folder/classes/class.ilObjFolder.php");
247  $newObj = new ilObjFolder();
248  $newObj->setType("fold");
249  break;
250 
251  case "WorkspaceFolder":
252  include_once("./Modules/WorkspaceFolder/classes/class.ilObjWorkspaceFolder.php");
253  $newObj = new ilObjWorkspaceFolder();
254  break;
255  }
256 
257  $newObj->setTitle($name);
258  $newObj->create();
259 
260  // repository
261  if (!$access_handler) {
262  $newObj->createReference();
263  $newObj->putInTree($ref_id);
264  $newObj->setPermissions($ref_id);
265 
266  if ($newObj->getType() == "cat") {
267  global $DIC;
268 
269  $lng = $DIC->language();
270  $newObj->addTranslation($name, "", $lng->getLangKey(), $lng->getLangKey());
271  }
272 
273  self::$new_files[$ref_id][] = $newObj;
274 
275  return $newObj->getRefId();
276  } // workspace
277  else {
278  $node_id = $tree->insertObject($ref_id, $newObj->getId());
279  $access_handler->setPermissions($ref_id, $node_id);
280 
281  return $node_id;
282  }
283  }
284 
285 
296  public static function createFile($filename, $path, $ref_id, $tree = null, $access_handler = null)
297  {
298  global $DIC;
299 
300  $rbacsystem = $DIC->rbac()->system();
301  $lng = $DIC->language();
302  $ilErr = $DIC["ilErr"];
303 
304  if (!$access_handler) {
305  $permission = $rbacsystem->checkAccess("create", $ref_id, "file");
306  } else {
307  $permission = $access_handler->checkAccess("create", "", $ref_id, "file");
308  }
309  if ($permission) {
310 
311  // create and insert file in grp_tree
312  include_once("./Modules/File/classes/class.ilObjFile.php");
313  $fileObj = new ilObjFile();
314  $fileObj->setType('file');
317 
318  // better use this, mime_content_type is deprecated
319  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
320  $fileObj->setFileType(ilObjMediaObject::getMimeType($path . "/" . $filename));
321  $fileObj->setFileSize(filesize($path . "/" . $filename));
322  $fileObj->create();
323 
324  // repository
325  if (!$access_handler) {
326  $fileObj->createReference();
327  $fileObj->putInTree($ref_id);
328  $fileObj->setPermissions($ref_id);
329 
330  self::$new_files[$ref_id][] = $fileObj;
331  } else {
332  $node_id = $tree->insertObject($ref_id, $fileObj->getId());
333  $access_handler->setPermissions($ref_id, $node_id);
334  }
335 
336  // upload file to filesystem
337  $fileObj->createDirectory();
338  $fileObj->storeUnzipedFile($path . "/" . $filename, ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename)));
339  } else {
340  $ilErr->raiseError($lng->txt("permission_denied"), $ilErr->MESSAGE);
341  }
342  }
343 
344 
348  public static function getNewObjects()
349  {
350  return self::$new_files;
351  }
352 
353 
363  public static function utf8_encode($string)
364  {
365 
366  // From http://w3.org/International/questions/qa-forms-utf-8.html
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);
377  }
378 
379 
388  public static function fastBase64Decode($filein, $fileout)
389  {
390  $fh = fopen($filein, 'rb');
391  $fh2 = fopen($fileout, 'wb');
392  stream_filter_append($fh2, 'convert.base64-decode');
393 
394  while (!feof($fh)) {
395  $chunk = fgets($fh);
396  if ($chunk === false) {
397  break;
398  }
399  fwrite($fh2, $chunk);
400  }
401  fclose($fh);
402  fclose($fh2);
403 
404  return true;
405  }
406 
407 
415  public function fastBase64Encode($filein, $fileout)
416  {
417  $fh = fopen($filein, 'rb');
418  $fh2 = fopen($fileout, 'wb');
419  stream_filter_append($fh2, 'convert.base64-encode');
420 
421  while (feof($fh)) {
422  $chunk = fgets($fh, 76);
423  if ($chunk === false) {
424  break;
425  }
426  fwrite($fh2, $chunk);
427  }
428  fclose($fh);
429  fclose($fh2);
430  }
431 
432 
443  private function fastGZip($in, $out, $level = "9")
444  {
445  if (!file_exists($in) || !is_readable($in)) {
446  return false;
447  }
448  if ((!file_exists($out) && !is_writable(dirname($out)) || (file_exists($out) && !is_writable($out)))) {
449  return false;
450  }
451 
452  $in_file = fopen($in, "rb");
453  if (!$out_file = gzopen($out, "wb" . $param)) {
454  return false;
455  }
456 
457  while (!feof($in_file)) {
458  $buffer = fgets($in_file, 4096);
459  gzwrite($out_file, $buffer, 4096);
460  }
461 
462  fclose($in_file);
463  gzclose($out_file);
464 
465  return true;
466  }
467 
468 
478  public function fastGunzip($in, $out)
479  {
480  if (!file_exists($in) || !is_readable($in)) {
481  return false;
482  }
483  if ((!file_exists($out) && !is_writable(dirname($out)) || (file_exists($out) && !is_writable($out)))) {
484  return false;
485  }
486 
487  $in_file = gzopen($in, "rb");
488  $out_file = fopen($out, "wb");
489 
490  while (!gzeof($in_file)) {
491  $buffer = gzread($in_file, 4096);
492  fwrite($out_file, $buffer, 4096);
493  }
494 
495  gzclose($in_file);
496  fclose($out_file);
497 
498  return true;
499  }
500 
501 
507  public static function lookupContentMimeType($content)
508  {
509  $finfo = new finfo(FILEINFO_MIME);
510 
511  return $finfo->buffer($content);
512  }
513 
514 
520  public static function lookupFileMimeType($a_file)
521  {
522  if (!file_exists($a_file) or !is_readable($a_file)) {
523  return false;
524  }
525 
526  return self::lookupContentMimeType(file_get_contents($a_file));
527  }
528 
529 
535  public static function _lookupMimeType($a_file)
536  {
537  return self::lookupFileMimeType($a_file);
538  }
539 
540 
546  public static function getValidExtensions()
547  {
548  global $DIC;
549 
550  $setting = $DIC->settings();
551 
552  // default white list
553  $whitelist = self::getDefaultValidExtensionWhiteList();
554 
555  // remove custom black list values
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]);
560  }
561  }
562 
563  // add custom white list values
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;
568  }
569  }
570 
571  // bugfix mantis 25498: add an empty entry to ensure that files without extensions are still valid
572  $whitelist[] = '';
573 
574  return $whitelist;
575  }
576 
577 
583  public static function getDefaultValidExtensionWhiteList()
584  {
585  return array(
586  '3gp', // VIDEO__3_GPP
587  '7z', // application/x-7z-compressed
588  'ai', // APPLICATION__POSTSCRIPT
589  'aif', // AUDIO__AIFF
590  'aifc', // AUDIO__AIFF
591  'aiff', // AUDIO__AIFF
592  'au', // AUDIO__BASIC
593  'arw', // IMAGE__X_SONY_ARW
594  'avi', // AUDIO__BASIC
595  'backup', // scorm wbts
596  'bak', // scorm wbts
597  'bas', // SPSS script
598  'bpmn', // bpmn
599  'bpmn2', // bpmn2
600  'bmp', // IMAGE__BMP
601  'bib', // bibtex
602  'bibtex', // bibtex
603  'bz', // APPLICATION__X_BZIP
604  'bz2', // APPLICATION__X_BZIP2
605  'c', // TEXT__PLAIN
606  'c++', // TEXT__PLAIN
607  'cc', // TEXT__PLAIN
608  'cct', // scorm wbts
609  'cdf', // (Wolfram) Computable Document Format
610  'cer', // APPLICATION__X_X509_CA_CERT
611  'class', // APPLICATION__X_JAVA_CLASS
612  'cls', // SPSS script
613  'conf', // TEXT__PLAIN
614  'cpp', // TEXT__X_C
615  'crt', // APPLICATION__X_X509_CA_CERT
616  'crs', // scorm wbts
617  'crw', // IMAGE__X_CANON_CRW
618  'cr2', // IMAGE__X_CANON_CR2
619  'css', // TEXT__CSS
620  'cst', // scorm wbts
621  'csv',
622  'cur', // scorm wbts
623  'db', // scorm wbts
624  'dcr', // scorm wbts
625  'des', // scorm wbts
626  'dng', // IMAGE__X_ADOBE_DNG
627  'doc', // APPLICATION__MSWORD,
628  'docx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_DOCUMENT,
629  'dot', // APPLICATION__MSWORD,
630  'dotx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_TEMPLATE,
631  'dtd',
632  'dvi', // APPLICATION__X_DVI,
633  'el', // TEXT__X_SCRIPT_ELISP,
634  'eps', // APPLICATION__POSTSCRIPT,
635  'epub', // APPLICATION__EPUB,
636  'f', // TEXT__X_FORTRAN,
637  'f77', // TEXT__X_FORTRAN,
638  'f90', // TEXT__X_FORTRAN,
639  'flv', // VIDEO__X_FLV,
640  'for', // TEXT__X_FORTRAN,
641  'g3', // IMAGE__G3FAX,
642  'gif', // IMAGE__GIF,
643  'gl', // VIDEO__GL,
644  'gan',
645  'gsd', // AUDIO__X_GSM,
646  'gsm', // AUDIO__X_GSM,
647  'gtar', // APPLICATION__X_GTAR,
648  'gz', // APPLICATION__X_GZIP,
649  'gzip', // APPLICATION__X_GZIP,
650  'h', // TEXT__X_C
651  'hpp', // TEXT__X_C
652  'htm', // TEXT__HTML,
653  'html', // TEXT__HTML,
654  'htmls', // TEXT__HTML,
655  'ibooks', // Apple IBook Format
656  'ico', // IMAGE__X_ICON,
657  'ics', // iCalendar, TEXT__CALENDAR
658  'ini', // scorm wbts
659  'ipynb', // iPython file for Jupyter Notebooks
660  'java', // TEXT__X_JAVA_SOURCE,
661  'jbf', // scorm wbts
662  'jpeg', // IMAGE__PJPEG,
663  'jpg', // IMAGE__JPEG,
664  'js', // APPLICATION__X_JAVASCRIPT,
665  'jsf', // scorm wbts
666  'jso', // scorm wbts
667  'json', // APPLICATION__JSON
668  'latex', // APPLICATION__X_LATEX,
669  'lang', // lang files
670  'less', // less
671  'log', // TEXT__PLAIN,
672  'lsp', // APPLICATION__X_LISP,
673  'ltx', // APPLICATION__X_LATEX,
674  'm1v', // VIDEO__MPEG,
675  'm2a', // AUDIO__MPEG,
676  'm2v', // VIDEO__MPEG,
677  'm3u', // AUDIO__X_MPEQURL,
678  'm4a', // AUDIO__MP4,
679  'm4v', // VIDEO__MP4,
680  'markdown', // TEXT__MARKDOWN,
681  'm', // MATLAB
682  'mat', // MATLAB
683  'md', // TEXT__MARKDOWN,
684  'mdl', // Vensim files
685  'mdown', // TEXT__MARKDOWN,
686  'mid', // AUDIO__MIDI,
687  'min', // scorm articulate?
688  'midi', // AUDIO__MIDI,
689  'mobi', // APPLICATION__X_MOBI,
690  'mod', // AUDIO__MOD,
691  'mov', // VIDEO__QUICKTIME,
692  'movie', // VIDEO__X_SGI_MOVIE,
693  'mp2', // AUDIO__X_MPEG,
694  'mp3', // AUDIO__X_MPEG3,
695  'mp4', // VIDEO__MP4,
696  'mpa', // AUDIO__MPEG,
697  'mpeg', // VIDEO__MPEG,
698  'mpg', // AUDIO__MPEG,
699  'mph', // COMSOL Multiphysics
700  'mpga', // AUDIO__MPEG,
701  'mpp', // APPLICATION__VND_MS_PROJECT,
702  'mpt', // APPLICATION__X_PROJECT,
703  'mpv', // APPLICATION__X_PROJECT,
704  'mpx', // APPLICATION__X_PROJECT,
705  'mv', // VIDEO__X_SGI_MOVIE,
706  'mw',
707  'mv4', // VIDEO__MP4,
708  'nb', // Wolfram Notebook files
709  'nbp', // Wolfram Notebook Player files
710  'nef', // IMAGE__X_NIKON_NEF,
711  'nif', // IMAGE__X_NIFF,
712  'niff', // IMAGE__X_NIFF,
713  'obj', // Wavefront .obj file
714  'obm', // SPSS script
715  'odt', // Open document text,
716  'ods', // Open document spreadsheet,
717  'odp', // Open document presentation,
718  'odg', // Open document graphics,
719  'odf', // Open document formula,
720  'oga', // AUDIO__OGG,
721  'ogg', // AUDIO__OGG,
722  'ogv', // VIDEO__OGG,
723  'old', // no real file extension, but used in mail/forum components,
724  'p', // TEXT__X_PASCAL,
725  'pas', // TEXT__PASCAL,
726  'pbm', // IMAGE__X_PORTABLE_BITMAP,
727  'pcl', // APPLICATION__VND_HP_PCL,
728  'pct', // IMAGE__X_PICT,
729  'pcx', // IMAGE__X_PCX,
730  'pdf', // APPLICATION__PDF,
731  'pgm', // IMAGE__X_PORTABLE_GRAYMAP,
732  'pic', // IMAGE__PICT,
733  'pict', // IMAGE__PICT,
734  'png', // IMAGE__PNG,
735  'por', // Portable SPSS file
736  'pov', // MODEL__X_POV,
737  'project', // scorm wbts
738  'properties', // scorm wbts
739  'ppa', // APPLICATION__VND_MS_POWERPOINT,
740  'ppm', // IMAGE__X_PORTABLE_PIXMAP,
741  'pps', // APPLICATION__VND_MS_POWERPOINT,
742  'ppsx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_SLIDESHOW,
743  'ppt', // APPLICATION__POWERPOINT,
744  'pptx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_PRESENTATION,
745  'ppz', // APPLICATION__MSPOWERPOINT,
746  'ps', // APPLICATION__POSTSCRIPT,
747  'psd', // scorm wbts
748  'pwz', // APPLICATION__VND_MS_POWERPOINT,
749  'qt', // VIDEO__QUICKTIME,
750  'qtc', // VIDEO__X_QTC,
751  'qti', // IMAGE__X_QUICKTIME,
752  'qtif', // IMAGE__X_QUICKTIME,
753  'r', // R script file
754  'ra', // AUDIO__X_PN_REALAUDIO,
755  'ram', // AUDIO__X_PN_REALAUDIO,
756  'rar', // RAR (application/vnd.rar)
757  'rast', // IMAGE__CMU_RASTER,
758  'rda', // R data file
759  'rev', // RAR (application/vnd.rar)
760  'rexx', // TEXT__X_SCRIPT_REXX,
761  'ris', // ris
762  'rf', // IMAGE__VND_RN_REALFLASH,
763  'rgb', // IMAGE__X_RGB,
764  'rm', // APPLICATION__VND_RN_REALMEDIA,
765  'rmd', // R Markdown file
766  'rmi', // AUDIO__MID,
767  'rmm', // AUDIO__X_PN_REALAUDIO,
768  'rmp', // AUDIO__X_PN_REALAUDIO,
769  'rt', // TEXT__RICHTEXT,
770  'rtf', // TEXT__RICHTEXT,
771  'rtx', // TEXT__RICHTEXT,
772  'rv', // VIDEO__VND_RN_REALVIDEO,
773  's', // TEXT__X_ASM,
774  's3m', // AUDIO__S3M,
775  'sav', // SPSS data file
776  'sbs', // SPSS script
777  'sec', //
778  'sdml', // TEXT__PLAIN,
779  'sgm', // TEXT__SGML,
780  'sgml', // TEXT__SGML
781  'smi', // APPLICATION__SMIL,
782  'smil', // APPLICATION__SMIL,
783  'sps', // SPSS syntax file
784  'spv', // SPSS output file
785  'stl', // Stereolithography CAD file
786  'svg', // IMAGE__SVG_XML,
787  'swa', // scorm wbts
788  'swf', // APPLICATION__X_SHOCKWAVE_FLASH,
789  'swz', // scorm wbts
790  'tar', // application/x-tar
791  'tex', // APPLICATION__X_TEX,
792  'texi', // APPLICATION__X_TEXINFO,
793  'texinfo', // APPLICATION__X_TEXINFO,
794  'text', // TEXT__PLAIN,
795  'tgz', // APPLICATION__X_COMPRESSED,
796  'tif', // IMAGE__TIFF,
797  'tiff', // IMAGE__TIFF,
798  'ttf', // scorm wbts
799  'txt', // TEXT__PLAIN,
800  'tmp',
801  'uvproj',
802  'vdf',
803  'vimeo', // VIDEO__VIMEO,
804  'viv', // VIDEO__VIMEO,
805  'vivo', // VIDEO__VIVO,
806  'vrml', // APPLICATION__X_VRML,
807  'vsdx', // viseo
808  'wav', // wav
809  'webm', // VIDEO__WEBM,
810  'wmv', // VIDEO__X_MS_WMV,
811  'wmx', // VIDEO__X_MS_WMX,
812  'wmz', // VIDEO__X_MS_WMZ,
813  'woff', // web open font format,
814  'wwd', // SPSS script
815  'xhtml', // APPLICATION__XHTML_XML,
816  'xif', // IMAGE__VND_XIFF,
817  'xls', // APPLICATION__EXCEL,
818  'xlsx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET,
819  'xmind',
820  'xml', // self::TEXT__XML,
821  'xsl', // APPLICATION__XML,
822  'xsd', // scorm
823  'zip' // APPLICATION__ZIP
824  );
825  }
826 
827 
836  public static function getValidFilename($a_filename)
837  {
838  if (!self::hasValidExtension($a_filename)) {
839  $pi = pathinfo($a_filename);
840  // if extension is not in white list, remove all "." and add ".sec" extension
841  $basename = str_replace(".", "", $pi["basename"]);
842  if (trim($basename) == "") {
843  include_once("./Services/Utilities/classes/class.ilFileUtilsException.php");
844  throw new ilFileUtilsException("Invalid upload filename.");
845  }
846  $basename .= ".sec";
847  if ($pi["dirname"] != "" && ($pi["dirname"] != "." || substr($a_filename, 0, 2) == "./")) {
848  $a_filename = $pi["dirname"] . "/" . $basename;
849  } else {
850  $a_filename = $basename;
851  }
852  }
853 
854  return $a_filename;
855  }
856 
857 
863  public static function hasValidExtension($a_filename)
864  {
865  $pi = pathinfo($a_filename);
866 
867  return (in_array(strtolower($pi["extension"]), self::getValidExtensions()));
868  }
869 
870 
880  public static function rename($a_source, $a_target)
881  {
882  $pi = pathinfo($a_target);
883  if (!in_array(strtolower($pi["extension"]), self::getValidExtensions())) {
884  include_once("./Services/Utilities/classes/class.ilFileUtilsException.php");
885  throw new ilFileUtilsException("Invalid target file " . $pi["basename"] . ".");
886  }
887 
888  return rename($a_source, $a_target);
889  }
890 }
global $ilErr
Definition: raiseError.php:16
Class ilObjFolder.
static getMimeType($a_file, $a_external=null)
get mime type for file
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
global $DIC
Definition: saml.php:7
static hasValidExtension($a_filename)
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.
if($format !==null) $name
Definition: metadata.php:146
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()
Valid extensions.
Create styles array
The data for the language used.
Class ilObjCategory.
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
Class ilObjWorkspaceFolder.
static utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
static fastBase64Decode($filein, $fileout)
decodes base encoded file row by row to prevent memory exhaust
fastGZip($in, $out, $level="9")
fast compressing the file with the zlib-extension without memory consumption
static getNewObjects()
global $lng
Definition: privfeed.php:17
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
$key
Definition: croninfo.php:18
static getValidFilename($a_filename)
Get valid filename.
Class to report exception.