ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilFileUtils Class Reference

Class ilFileUtils. More...

+ Collaboration diagram for ilFileUtils:

Public Member Functions

 fastBase64Encode ($filein, $fileout)
 decodes base encoded file row by row to prevent memory exhaust More...
 
 fastGunzip ($in, $out)
 fast uncompressing the file with the zlib-extension without memory consumption More...
 

Static Public Member Functions

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 More...
 
static recursive_dirscan ($dir, &$arr)
 Recursively scans a given directory and writes path and filename into referenced array. More...
 
static createObjects ($dir, $structure, $ref_id, $containerType, $tree=null, $access_handler=null)
 Recursively scans a given directory and creates file and folder/category objects. More...
 
static createContainer ($name, $ref_id, $containerType, $tree=null, $access_handler=null)
 Creates and inserts container object (folder/category) into tree. More...
 
static createFile ($filename, $path, $ref_id, $tree=null, $access_handler=null)
 Creates and inserts file object into tree. More...
 
static getNewObjects ()
 
static utf8_encode ($string)
 utf8-encodes string if it is not a valid utf8-string. More...
 
static fastBase64Decode ($filein, $fileout)
 decodes base encoded file row by row to prevent memory exhaust More...
 
static lookupContentMimeType ($content)
 
static lookupFileMimeType ($a_file)
 
static _lookupMimeType ($a_file)
 
static getValidExtensions ()
 Valid extensions. More...
 
static getDefaultValidExtensionWhiteList ()
 Valid extensions. More...
 
static getValidFilename ($a_filename)
 Get valid filename. More...
 
static hasValidExtension ($a_filename)
 
static rename ($a_source, $a_target)
 Rename a file. More...
 

Static Protected Attributes

static $new_files = array()
 

Private Member Functions

 fastGZip ($in, $out, $level="9")
 fast compressing the file with the zlib-extension without memory consumption More...
 

Detailed Description

Class ilFileUtils.

Deprecated:
All Methods are widely used and there is currently no other service providing all of them, but please do not implement new methods in this class.
Author
Jan Hippchen janhi.nosp@m.ppch.nosp@m.en@gm.nosp@m.x.de

Definition at line 38 of file class.ilFileUtils.php.

Member Function Documentation

◆ _lookupMimeType()

static ilFileUtils::_lookupMimeType (   $a_file)
static
Parameters
stringfile absolute path to file
Returns
string $mimeType

Definition at line 535 of file class.ilFileUtils.php.

Referenced by ilFileXMLParser\handlerEndTag().

536  {
537  return self::lookupFileMimeType($a_file);
538  }
+ Here is the caller graph for this function:

◆ createContainer()

static ilFileUtils::createContainer (   $name,
  $ref_id,
  $containerType,
  $tree = null,
  $access_handler = null 
)
static

Creates and inserts container object (folder/category) into tree.

Parameters
string$nameName of the object
integer$ref_idref_id of parent
string$containerTypeFold or Cat
Returns
integer ref_id of containerobject
Author
Jan Hippchen
Version
1.6.9.07

Definition at line 236 of file class.ilFileUtils.php.

References $DIC, $lng, $name, and $tree.

Referenced by createObjects().

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  }
Class ilObjFolder.
global $DIC
Definition: saml.php:7
$lng
Class ilObjCategory.
Class ilObjWorkspaceFolder.
+ Here is the caller graph for this function:

◆ createFile()

static ilFileUtils::createFile (   $filename,
  $path,
  $ref_id,
  $tree = null,
  $access_handler = null 
)
static

Creates and inserts file object into tree.

Parameters
string$filenameName of the object
string$pathPath to file
integer$ref_idref_id of parent
Version
1.6.9.07
Author
Jan Hippchen

Definition at line 296 of file class.ilFileUtils.php.

References $DIC, $filename, $ilErr, $lng, $path, $tree, ilObjMediaObject\getMimeType(), ilUtil\stripSlashes(), and utf8_encode().

Referenced by createObjects().

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  }
$path
Definition: aliased.php:25
static getMimeType($a_file, $a_external=null)
get mime type for file
global $DIC
Definition: saml.php:7
$ilErr
Definition: raiseError.php:18
$lng
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$filename
Definition: buildRTE.php:89
static utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createObjects()

static ilFileUtils::createObjects (   $dir,
  $structure,
  $ref_id,
  $containerType,
  $tree = null,
  $access_handler = null 
)
static

Recursively scans a given directory and creates file and folder/category objects.

Calls createContainer & createFile to store objects in tree

Parameters
string$dirDirectory to start from
booleanstructure True if archive structure is to be overtaken (otherwise flat inclusion)
integer$ref_idref_id of parent object, if null, files won�t be included in system (just checked)
stringcontainerType object type of created containerobjects (folder or category)
Returns
integer errorcode
Exceptions
ilFileUtilsException
Author
Jan Hippchen
Version
1.6.9.07

Definition at line 198 of file class.ilFileUtils.php.

References ilFileUtilsException\$BROKEN_FILE, $lng, $tree, createContainer(), createFile(), and utf8_encode().

Referenced by processZipFile().

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  }
static createFile($filename, $path, $ref_id, $tree=null, $access_handler=null)
Creates and inserts file object into tree.
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.
$lng
static utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
Class to report exception.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fastBase64Decode()

static ilFileUtils::fastBase64Decode (   $filein,
  $fileout 
)
static

decodes base encoded file row by row to prevent memory exhaust

Parameters
string$filenamename of file to read
string$fileoutname where to put decoded file
Returns
bool

Definition at line 388 of file class.ilFileUtils.php.

Referenced by ilFileXMLParser\handlerEndTag().

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  }
+ Here is the caller graph for this function:

◆ fastBase64Encode()

ilFileUtils::fastBase64Encode (   $filein,
  $fileout 
)

decodes base encoded file row by row to prevent memory exhaust

Parameters
string$filenamename of file to read
Returns
string base decoded content

Definition at line 415 of file class.ilFileUtils.php.

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  }

◆ fastGunzip()

ilFileUtils::fastGunzip (   $in,
  $out 
)

fast uncompressing the file with the zlib-extension without memory consumption

Parameters
string$infilename
string$outfilename
Returns
bool

Definition at line 478 of file class.ilFileUtils.php.

References $in, and $out.

Referenced by ilFileXMLParser\handlerEndTag().

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  }
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
+ Here is the caller graph for this function:

◆ fastGZip()

ilFileUtils::fastGZip (   $in,
  $out,
  $level = "9" 
)
private

fast compressing the file with the zlib-extension without memory consumption

Parameters
string$infilename
string$outfilename
string$levelcompression level from 1 to 9
Returns
bool

Definition at line 443 of file class.ilFileUtils.php.

References $in, and $out.

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  }
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37

◆ getDefaultValidExtensionWhiteList()

static ilFileUtils::getDefaultValidExtensionWhiteList ( )
static

Valid extensions.

Returns
array valid file extensions

Definition at line 583 of file class.ilFileUtils.php.

Referenced by ilObjFileAccessSettingsGUI\initUploadSettingsForm().

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  'ggb', // GEOGEBRA
646  'gsd', // AUDIO__X_GSM,
647  'gsm', // AUDIO__X_GSM,
648  'gtar', // APPLICATION__X_GTAR,
649  'gz', // APPLICATION__X_GZIP,
650  'gzip', // APPLICATION__X_GZIP,
651  'h', // TEXT__X_C
652  'hpp', // TEXT__X_C
653  'htm', // TEXT__HTML,
654  'html', // TEXT__HTML,
655  'htmls', // TEXT__HTML,
656  'ibooks', // Apple IBook Format
657  'ico', // IMAGE__X_ICON,
658  'ics', // iCalendar, TEXT__CALENDAR
659  'ini', // scorm wbts
660  'ipynb', // iPython file for Jupyter Notebooks
661  'java', // TEXT__X_JAVA_SOURCE,
662  'jbf', // scorm wbts
663  'jpeg', // IMAGE__PJPEG,
664  'jpg', // IMAGE__JPEG,
665  'js', // APPLICATION__X_JAVASCRIPT,
666  'jsf', // scorm wbts
667  'jso', // scorm wbts
668  'json', // APPLICATION__JSON
669  'latex', // APPLICATION__X_LATEX,
670  'lang', // lang files
671  'less', // less
672  'log', // TEXT__PLAIN,
673  'lsp', // APPLICATION__X_LISP,
674  'ltx', // APPLICATION__X_LATEX,
675  'm1v', // VIDEO__MPEG,
676  'm2a', // AUDIO__MPEG,
677  'm2v', // VIDEO__MPEG,
678  'm3u', // AUDIO__X_MPEQURL,
679  'm4a', // AUDIO__MP4,
680  'm4v', // VIDEO__MP4,
681  'markdown', // TEXT__MARKDOWN,
682  'm', // MATLAB
683  'mat', // MATLAB
684  'md', // TEXT__MARKDOWN,
685  'mdl', // Vensim files
686  'mdown', // TEXT__MARKDOWN,
687  'mid', // AUDIO__MIDI,
688  'min', // scorm articulate?
689  'midi', // AUDIO__MIDI,
690  'mobi', // APPLICATION__X_MOBI,
691  'mod', // AUDIO__MOD,
692  'mov', // VIDEO__QUICKTIME,
693  'movie', // VIDEO__X_SGI_MOVIE,
694  'mp2', // AUDIO__X_MPEG,
695  'mp3', // AUDIO__X_MPEG3,
696  'mp4', // VIDEO__MP4,
697  'mpa', // AUDIO__MPEG,
698  'mpeg', // VIDEO__MPEG,
699  'mpg', // AUDIO__MPEG,
700  'mph', // COMSOL Multiphysics
701  'mpga', // AUDIO__MPEG,
702  'mpp', // APPLICATION__VND_MS_PROJECT,
703  'mpt', // APPLICATION__X_PROJECT,
704  'mpv', // APPLICATION__X_PROJECT,
705  'mpx', // APPLICATION__X_PROJECT,
706  'mv', // VIDEO__X_SGI_MOVIE,
707  'mw',
708  'mv4', // VIDEO__MP4,
709  'nb', // Wolfram Notebook files
710  'nbp', // Wolfram Notebook Player files
711  'nef', // IMAGE__X_NIKON_NEF,
712  'nif', // IMAGE__X_NIFF,
713  'niff', // IMAGE__X_NIFF,
714  'obj', // Wavefront .obj file
715  'obm', // SPSS script
716  'odt', // Open document text,
717  'ods', // Open document spreadsheet,
718  'odp', // Open document presentation,
719  'odg', // Open document graphics,
720  'odf', // Open document formula,
721  'oga', // AUDIO__OGG,
722  'ogg', // AUDIO__OGG,
723  'ogv', // VIDEO__OGG,
724  'old', // no real file extension, but used in mail/forum components,
725  'p', // TEXT__X_PASCAL,
726  'pas', // TEXT__PASCAL,
727  'pbm', // IMAGE__X_PORTABLE_BITMAP,
728  'pcl', // APPLICATION__VND_HP_PCL,
729  'pct', // IMAGE__X_PICT,
730  'pcx', // IMAGE__X_PCX,
731  'pdf', // APPLICATION__PDF,
732  'pgm', // IMAGE__X_PORTABLE_GRAYMAP,
733  'pic', // IMAGE__PICT,
734  'pict', // IMAGE__PICT,
735  'png', // IMAGE__PNG,
736  'por', // Portable SPSS file
737  'pov', // MODEL__X_POV,
738  'project', // scorm wbts
739  'properties', // scorm wbts
740  'ppa', // APPLICATION__VND_MS_POWERPOINT,
741  'ppm', // IMAGE__X_PORTABLE_PIXMAP,
742  'pps', // APPLICATION__VND_MS_POWERPOINT,
743  'ppsx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_SLIDESHOW,
744  'ppt', // APPLICATION__POWERPOINT,
745  'pptx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_PRESENTATION,
746  'ppz', // APPLICATION__MSPOWERPOINT,
747  'ps', // APPLICATION__POSTSCRIPT,
748  'psd', // scorm wbts
749  'pwz', // APPLICATION__VND_MS_POWERPOINT,
750  'qt', // VIDEO__QUICKTIME,
751  'qtc', // VIDEO__X_QTC,
752  'qti', // IMAGE__X_QUICKTIME,
753  'qtif', // IMAGE__X_QUICKTIME,
754  'r', // R script file
755  'ra', // AUDIO__X_PN_REALAUDIO,
756  'ram', // AUDIO__X_PN_REALAUDIO,
757  'rar', // RAR (application/vnd.rar)
758  'rast', // IMAGE__CMU_RASTER,
759  'rda', // R data file
760  'rev', // RAR (application/vnd.rar)
761  'rexx', // TEXT__X_SCRIPT_REXX,
762  'ris', // ris
763  'rf', // IMAGE__VND_RN_REALFLASH,
764  'rgb', // IMAGE__X_RGB,
765  'rm', // APPLICATION__VND_RN_REALMEDIA,
766  'rmd', // R Markdown file
767  'rmi', // AUDIO__MID,
768  'rmm', // AUDIO__X_PN_REALAUDIO,
769  'rmp', // AUDIO__X_PN_REALAUDIO,
770  'rt', // TEXT__RICHTEXT,
771  'rtf', // TEXT__RICHTEXT,
772  'rtx', // TEXT__RICHTEXT,
773  'rv', // VIDEO__VND_RN_REALVIDEO,
774  's', // TEXT__X_ASM,
775  's3m', // AUDIO__S3M,
776  'sav', // SPSS data file
777  'sbs', // SPSS script
778  'sec', //
779  'sdml', // TEXT__PLAIN,
780  'sgm', // TEXT__SGML,
781  'sgml', // TEXT__SGML
782  'smi', // APPLICATION__SMIL,
783  'smil', // APPLICATION__SMIL,
784  'sps', // SPSS syntax file
785  'spv', // SPSS output file
786  'stl', // Stereolithography CAD file
787  'svg', // IMAGE__SVG_XML,
788  'swa', // scorm wbts
789  'swf', // APPLICATION__X_SHOCKWAVE_FLASH,
790  'swz', // scorm wbts
791  'tar', // application/x-tar
792  'tex', // APPLICATION__X_TEX,
793  'texi', // APPLICATION__X_TEXINFO,
794  'texinfo', // APPLICATION__X_TEXINFO,
795  'text', // TEXT__PLAIN,
796  'tgz', // APPLICATION__X_COMPRESSED,
797  'tif', // IMAGE__TIFF,
798  'tiff', // IMAGE__TIFF,
799  'ttf', // scorm wbts
800  'txt', // TEXT__PLAIN,
801  'tmp',
802  'uvproj',
803  'vdf',
804  'vimeo', // VIDEO__VIMEO,
805  'viv', // VIDEO__VIMEO,
806  'vivo', // VIDEO__VIVO,
807  'vrml', // APPLICATION__X_VRML,
808  'vsdx', // viseo
809  'wav', // wav
810  'webm', // VIDEO__WEBM,
811  'wmv', // VIDEO__X_MS_WMV,
812  'wmx', // VIDEO__X_MS_WMX,
813  'wmz', // VIDEO__X_MS_WMZ,
814  'woff', // web open font format,
815  'wwd', // SPSS script
816  'xhtml', // APPLICATION__XHTML_XML,
817  'xif', // IMAGE__VND_XIFF,
818  'xls', // APPLICATION__EXCEL,
819  'xlsx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET,
820  'xmind',
821  'xml', // self::TEXT__XML,
822  'xsl', // APPLICATION__XML,
823  'xsd', // scorm
824  'zip' // APPLICATION__ZIP
825  );
826  }
+ Here is the caller graph for this function:

◆ getNewObjects()

static ilFileUtils::getNewObjects ( )
static
Returns
array

Definition at line 348 of file class.ilFileUtils.php.

Referenced by ilObjFileGUI\uploadFiles().

349  {
350  return self::$new_files;
351  }
+ Here is the caller graph for this function:

◆ getValidExtensions()

static ilFileUtils::getValidExtensions ( )
static

Valid extensions.

Returns
array valid file extensions

Definition at line 546 of file class.ilFileUtils.php.

References $DIC, and $key.

Referenced by ILIAS\Filesystem\Security\Sanitizing\FilenameSanitizerImpl\__construct(), ILIAS\Filesystem\Decorator\FilesystemWhitelistDecorator\__construct(), and ilObjFileAccessSettingsGUI\initUploadSettingsForm().

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  }
global $DIC
Definition: saml.php:7
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ getValidFilename()

static ilFileUtils::getValidFilename (   $a_filename)
static

Get valid filename.

Parameters
stringfilename
Returns
string valid upload filename
Exceptions
ilFileUtilsException

Definition at line 837 of file class.ilFileUtils.php.

Referenced by ilFileVersionTableGUI\__construct(), ilFileDataMail\deliverAttachmentsAsZip(), ilPortfolioCertificateFileService\deliverCertificate(), ilObjFile\determineFileSize(), ilFileVersionsTableGUI\fillRow(), ilWebDAVRepositoryHelper\getFilenameWithSanitizedFileExtension(), ilObjFileDAV\getName(), ilObjFileDAV\getPathToFile(), ilCertificateFileUtilsHelper\getValidFilename(), ilWebDAVObjDAVHelper\isValidFileNameWithValidFileExtension(), ILIAS\File\Sanitation\FilePathSanitizer\needsSanitation(), ILIAS\File\Sanitation\FilePathSanitizer\santitizeFilename(), assFileUpload\saveWorkingData(), ilObjFile\storeUnzipedFile(), ilFSStorageExercise\uploadFile(), ilExSubmission\uploadFile(), ilBadgeImageTemplate\uploadImage(), and ilUtil\virusHandling().

838  {
839  if (!self::hasValidExtension($a_filename)) {
840  $pi = pathinfo($a_filename);
841  // if extension is not in white list, remove all "." and add ".sec" extension
842  $basename = str_replace(".", "", $pi["basename"]);
843  if (trim($basename) == "") {
844  include_once("./Services/Utilities/classes/class.ilFileUtilsException.php");
845  throw new ilFileUtilsException("Invalid upload filename.");
846  }
847  $basename .= ".sec";
848  if ($pi["dirname"] != "" && ($pi["dirname"] != "." || substr($a_filename, 0, 2) == "./")) {
849  $a_filename = $pi["dirname"] . "/" . $basename;
850  } else {
851  $a_filename = $basename;
852  }
853  }
854 
855  return $a_filename;
856  }
Class to report exception.
+ Here is the caller graph for this function:

◆ hasValidExtension()

static ilFileUtils::hasValidExtension (   $a_filename)
static
Parameters
string$a_filename
Returns
bool

Definition at line 864 of file class.ilFileUtils.php.

Referenced by ilObjFileGUI\uploadFiles().

865  {
866  $pi = pathinfo($a_filename);
867 
868  return (in_array(strtolower($pi["extension"]), self::getValidExtensions()));
869  }
+ Here is the caller graph for this function:

◆ lookupContentMimeType()

static ilFileUtils::lookupContentMimeType (   $content)
static
Parameters
string$content
Returns
string $mimeType

Definition at line 507 of file class.ilFileUtils.php.

Referenced by ilQtiMatImageSecurity\determineMimeType().

508  {
509  $finfo = new finfo(FILEINFO_MIME);
510 
511  return $finfo->buffer($content);
512  }
+ Here is the caller graph for this function:

◆ lookupFileMimeType()

static ilFileUtils::lookupFileMimeType (   $a_file)
static
Parameters
string$a_file
Returns
string $mimeType

Definition at line 520 of file class.ilFileUtils.php.

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  }

◆ processZipFile()

static ilFileUtils::processZipFile (   $a_directory,
  $a_file,
  $structure,
  $ref_id = null,
  $containerType = null,
  $tree = null,
  $access_handler = null 
)
static

unzips in given directory and processes uploaded zip for use as single files

Parameters
string$a_directoryDirectory to unzip
string$a_fileFilename of archive
booleanstructure True if archive structure is to be overtaken
integer$ref_idref_id of parent object, if null, files wont be included in system (just checked)
stringcontainerType object type of created containerobjects (folder or category)
Exceptions
ilFileUtilsException
ilException
Author
Jan Hippchen
Version
1.6.9.07

Definition at line 62 of file class.ilFileUtils.php.

References ilFileUtilsException\$BROKEN_FILE, $DIC, ilFileUtilsException\$DOUBLETTES_FOUND, ilFileUtilsException\$INFECTED_FILE, $key, $lng, $tree, createObjects(), ilUtil\delDir(), recursive_dirscan(), ilUtil\unzip(), utf8_encode(), and ilUtil\virusHandling().

Referenced by ilCloudPluginUploadGUI\handleFileUpload(), ilExSubmission\processUploadedZipFile(), ilObjFileGUI\saveUnzip(), and ilObjFileGUI\uploadFiles().

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  }
static virusHandling($a_file, $a_orig_name="", $a_clean=true)
scan file for viruses and clean files if possible
global $DIC
Definition: saml.php:7
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. ...
$lng
static utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
$key
Definition: croninfo.php:18
Class to report exception.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ recursive_dirscan()

static ilFileUtils::recursive_dirscan (   $dir,
$arr 
)
static

Recursively scans a given directory and writes path and filename into referenced array.

Parameters
string$dirDirectory to start from
array&$arrReferenced array which is filled with Filename and path
Exceptions
ilFileUtilsException
Version
1.6.9.07
Author
Jan Hippchen

Definition at line 156 of file class.ilFileUtils.php.

References ilFileUtilsException\$BROKEN_FILE, $DIC, and $lng.

Referenced by ilObjFileBasedLMGUI\afterSave(), ilSCORM13Package\dbImportSco(), ilSCORM2004Asset\exportPDF(), ilObjSCORM2004LearningModule\exportPDF(), ilObjTest\getCustomStyles(), ilExSubmission\processUploadedZipFile(), processZipFile(), ilUtil\unzip(), and ilFileSystemGUI\unzipFile().

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  }
global $DIC
Definition: saml.php:7
$lng
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
Class to report exception.
+ Here is the caller graph for this function:

◆ rename()

static ilFileUtils::rename (   $a_source,
  $a_target 
)
static

Rename a file.

Parameters
$a_source
$a_target
Returns
bool
Exceptions
ilFileUtilsException

Definition at line 881 of file class.ilFileUtils.php.

Referenced by ilAssFileUploadUploadsExporter\createFileUploadCollectionZipFile(), ilPhantomJSRenderer\generatePDF(), ilFileDataForum\getForumPath(), ilScorm2004DataSet\getXmlRecord(), ilScorm2004DataSet\importRecord(), ilScormAiccImporter\importXmlRepresentation(), assFlashQuestion\moveAppletIfExists(), ilObjSCORMLearningModuleGUI\newModuleVersionUpload(), ilFileSystemGUI\renameFile(), ilFileXMLParser\setFileContents(), ilObjFile\storeUnzipedFile(), and ilObjSAHSLearningModuleGUI\uploadObject().

882  {
883  $pi = pathinfo($a_target);
884  if (!in_array(strtolower($pi["extension"]), self::getValidExtensions())) {
885  include_once("./Services/Utilities/classes/class.ilFileUtilsException.php");
886  throw new ilFileUtilsException("Invalid target file");
887  }
888 
889  return rename($a_source, $a_target);
890  }
static rename($a_source, $a_target)
Rename a file.
Class to report exception.
+ Here is the caller graph for this function:

◆ utf8_encode()

static ilFileUtils::utf8_encode (   $string)
static

utf8-encodes string if it is not a valid utf8-string.

Parameters
string$stringString to encode
Returns
string utf-8-encoded string
Author
Jan Hippchen
Version
1.12.3.08

Definition at line 363 of file class.ilFileUtils.php.

Referenced by createFile(), createObjects(), ilSCORM13Package\dbImportSco(), ilExSubmission\processUploadedZipFile(), and processZipFile().

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  }
static utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
+ Here is the caller graph for this function:

Field Documentation

◆ $new_files

ilFileUtils::$new_files = array()
staticprotected

Definition at line 44 of file class.ilFileUtils.php.


The documentation for this class was generated from the following file: