ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilFileUtils Class Reference

fileUtils class various functions for zip-archive handling More...

+ Collaboration diagram for ilFileUtils:

Public Member Functions

 fastBase64Decode ($filein, $fileout)
 decodes base encoded file row by row to prevent memory exhaust More...
 
 fastBase64Encode ($filein, $fileout)
 decodes base encoded file row by row to prevent memory exhaust More...
 
 fastGZip ($in, $out, $level="9")
 fast compressing the file with the zlib-extension without memory consumption 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 lookupContentMimeType ($content)
 
static lookupFileMimeType ($a_file)
 
static _lookupMimeType ($a_file)
 
static getValidExtensions ()
 
static getDefaultValidExtensionWhiteList ()
 Valid extensions. More...
 
static getValidFilename ($a_filename)
 Get valid filename. More...
 
static rename ($a_source, $a_target)
 Rename a file. More...
 

Static Protected Attributes

static $new_files = array()
 

Detailed Description

fileUtils class various functions for zip-archive handling

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 524 of file class.ilFileUtils.php.

Referenced by ilFileXMLParser\handlerEndTag().

525  {
526  return self::lookupFileMimeType($a_file);
527  }
+ 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.

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

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

References $lng, and $ref_id.

Referenced by createObjects().

250  {
251  switch($containerType)
252  {
253  case "Category":
254  include_once("./Modules/Category/classes/class.ilObjCategory.php");
255  $newObj = new ilObjCategory();
256  $newObj->setType("cat");
257  break;
258 
259  case "Folder":
260  include_once("./Modules/Folder/classes/class.ilObjFolder.php");
261  $newObj = new ilObjFolder();
262  $newObj->setType("fold");
263  break;
264 
265  case "WorkspaceFolder":
266  include_once("./Modules/WorkspaceFolder/classes/class.ilObjWorkspaceFolder.php");
267  $newObj = new ilObjWorkspaceFolder();
268  break;
269  }
270 
271  $newObj->setTitle($name);
272  $newObj->create();
273 
274  // repository
275  if(!$access_handler)
276  {
277  $newObj->createReference();
278  $newObj->putInTree($ref_id);
279  $newObj->setPermissions($ref_id);
280 
281  if ($newObj->getType() == "cat")
282  {
283  global $lng;
284  $newObj->addTranslation($name,"", $lng->getLangKey(), $lng->getLangKey());
285  }
286 
287  self::$new_files[$ref_id][] = $newObj;
288 
289  return $newObj->getRefId();
290  }
291  // workspace
292  else
293  {
294  $node_id = $tree->insertObject($ref_id, $newObj->getId());
295  $access_handler->setPermissions($ref_id, $node_id);
296 
297  return $node_id;
298  }
299  }
Class ilObjFolder.
Class ilObjCategory.
Class ilObjWorkspaceFolder.
$ref_id
Definition: sahs_server.php:39
global $lng
Definition: privfeed.php:17
+ 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.

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

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

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

Referenced by createObjects().

311  {
312  global $rbacsystem, $lng, $ilErr;
313 
314  if(!$access_handler)
315  {
316  $permission = $rbacsystem->checkAccess("create", $ref_id, "file");
317  }
318  else
319  {
320  $permission = $access_handler->checkAccess("create", "", $ref_id, "file");
321  }
322  if ($permission) {
323 
324  // create and insert file in grp_tree
325  include_once("./Modules/File/classes/class.ilObjFile.php");
326  $fileObj = new ilObjFile();
327  $fileObj->setType('file');
330 
331  // better use this, mime_content_type is deprecated
332  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
333  $fileObj->setFileType(ilObjMediaObject::getMimeType($path. "/" . $filename));
334  $fileObj->setFileSize(filesize($path. "/" . $filename));
335  $fileObj->create();
336 
337  // repository
338  if(!$access_handler)
339  {
340  $fileObj->createReference();
341  $fileObj->putInTree($ref_id);
342  $fileObj->setPermissions($ref_id);
343 
344  self::$new_files[$ref_id][] = $fileObj;
345  }
346  else
347  {
348  $node_id = $tree->insertObject($ref_id, $fileObj->getId());
349  $access_handler->setPermissions($ref_id, $node_id);
350  }
351 
352  // upload file to filesystem
353  $fileObj->createDirectory();
354  $fileObj->storeUnzipedFile($path. "/" . $filename,ilFileUtils::utf8_encode(ilUtil::stripSlashes($filename)));
355  }
356  else {
357  $ilErr->raiseError($lng->txt("permission_denied"),$ilErr->MESSAGE);
358  }
359  }
global $ilErr
Definition: raiseError.php:16
$path
Definition: aliased.php:25
Class ilObjFile.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
static getMimeType($a_file, $a_external=false)
get mime type for file
$ref_id
Definition: sahs_server.php:39
global $lng
Definition: privfeed.php:17
+ 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

Author
Jan Hippchen
Version
1.6.9.07
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

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

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

Referenced by processZipFile().

204  {
205  $dirlist = opendir($dir);
206 
207  while (false !== ($file = readdir ($dirlist)))
208  {
209  if (!is_file($dir . "/" . $file) && !is_dir($dir . "/" . $file))
210  {
211  throw new ilFileUtilsException($lng->txt("filenames_not_supported") , ilFileUtilsException::$BROKEN_FILE);
212  }
213  if ($file != '.' && $file != '..')
214  {
215  $newpath = $dir.'/'.$file;
216  $level = explode('/',$newpath);
217  if (is_dir($newpath))
218  {
219  if ($structure)
220  {
221  $new_ref_id = ilFileUtils::createContainer(ilFileUtils::utf8_encode($file), $ref_id, $containerType, $tree, $access_handler);
222  ilFileUtils::createObjects($newpath, $structure, $new_ref_id, $containerType, $tree, $access_handler);
223  }
224  else
225  {
226  ilFileUtils::createObjects($newpath, $structure, $ref_id, $containerType, $tree, $access_handler);
227  }
228  }
229  else
230  {
231  ilFileUtils::createFile (end($level), $dir, $ref_id, $tree, $access_handler);
232  }
233  }
234  }
235  closedir($dirlist);
236  }
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.
static utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
$ref_id
Definition: sahs_server.php:39
global $lng
Definition: privfeed.php:17
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
Class to report exception.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fastBase64Decode()

ilFileUtils::fastBase64Decode (   $filein,
  $fileout 
)

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

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

References $fh.

Referenced by ilFileXMLParser\handlerEndTag().

396  {
397  $fh = fopen($filein, 'rb');
398  $fh2= fopen($fileout, 'wb');
399  stream_filter_append($fh2, 'convert.base64-decode');
400 
401  while (!feof($fh)){
402  $chunk = fgets($fh);
403  if ($chunk === false)
404  break;
405  fwrite ($fh2, $chunk);
406  }
407  fclose ($fh);
408  fclose ($fh2);
409  return true;
410  }
+ 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 417 of file class.ilFileUtils.php.

References $fh.

418  {
419  $fh = fopen($filein, 'rb');
420  $fh2= fopen($fileout, 'wb');
421  stream_filter_append($fh2, 'convert.base64-encode');
422 
423  while (feof ($fh)) {
424  $chunk = fgets($fh,76);
425  if ($chunk === false)
426  {
427  break;
428  }
429  fwrite ($fh2, $chunk);
430  }
431  fclose ($fh);
432  fclose ($fh2);
433  }

◆ 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 475 of file class.ilFileUtils.php.

References $in, and $out.

Referenced by ilFileXMLParser\handlerEndTag().

476  {
477  if (!file_exists ($in) || !is_readable ($in))
478  return false;
479  if ((!file_exists ($out) && !is_writable (dirname ($out)) || (file_exists($out) && !is_writable($out)) ))
480  return false;
481 
482  $in_file = gzopen ($in, "rb");
483  $out_file = fopen ($out, "wb");
484 
485  while (!gzeof ($in_file)) {
486  $buffer = gzread ($in_file, 4096);
487  fwrite ($out_file, $buffer, 4096);
488  }
489 
490  gzclose ($in_file);
491  fclose ($out_file);
492 
493  return true;
494  }
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" 
)

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 444 of file class.ilFileUtils.php.

References $in, and $out.

445  {
446  if (!file_exists ($in) || !is_readable ($in))
447  return false;
448  if ((!file_exists ($out) && !is_writable (dirname ($out)) || (file_exists($out) && !is_writable($out)) ))
449  return false;
450 
451  $in_file = fopen ($in, "rb");
452  if (!$out_file = gzopen ($out, "wb".$param)) {
453  return false;
454  }
455 
456  while (!feof ($in_file)) {
457  $buffer = fgets ($in_file, 4096);
458  gzwrite ($out_file, $buffer, 4096);
459  }
460 
461  fclose ($in_file);
462  gzclose ($out_file);
463 
464  return true;
465  }
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 562 of file class.ilFileUtils.php.

References array.

Referenced by ilObjFileAccessSettingsGUI\initUploadSettingsForm().

563  {
564  return array(
565  '3gp', // VIDEO__3_GPP
566  'ai', // APPLICATION__POSTSCRIPT
567  'aif', // AUDIO__AIFF
568  'aifc', // AUDIO__AIFF
569  'aiff', // AUDIO__AIFF
570  'au', // AUDIO__BASIC
571  'arw', // IMAGE__X_SONY_ARW
572  'avi', // AUDIO__BASIC
573  'backup', // scorm wbts
574  'bak', // scorm wbts
575  'bpmn', // bpmn
576  'bpmn2', // bpmn2
577  'bmp', // IMAGE__BMP
578  'bib', // bibtex
579  'bibtex', // bibtex
580  'bz', // APPLICATION__X_BZIP
581  'bz2', // APPLICATION__X_BZIP2
582  'c', // TEXT__PLAIN
583  'c++', // TEXT__PLAIN
584  'cc', // TEXT__PLAIN
585  'cct', // scorm wbts
586  'cer', // APPLICATION__X_X509_CA_CERT
587  'class', // APPLICATION__X_JAVA_CLASS
588  'conf', // TEXT__PLAIN
589  'cpp', // TEXT__X_C
590  'crt', // APPLICATION__X_X509_CA_CERT
591  'crs', // scorm wbts
592  'crw', // IMAGE__X_CANON_CRW
593  'cr2', // IMAGE__X_CANON_CR2
594  'css', // TEXT__CSS
595  'cst', // scorm wbts
596  'csv',
597  'cur', // scorm wbts
598  'db', // scorm wbts
599  'dcr', // scorm wbts
600  'des', // scorm wbts
601  'dng', // IMAGE__X_ADOBE_DNG
602  'doc', // APPLICATION__MSWORD,
603  'docx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_DOCUMENT,
604  'dot', // APPLICATION__MSWORD,
605  'dotx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_TEMPLATE,
606  'dtd',
607  'dvi', // APPLICATION__X_DVI,
608  'el', // TEXT__X_SCRIPT_ELISP,
609  'eps', // APPLICATION__POSTSCRIPT,
610  'epub', // APPLICATION__EPUB,
611  'f', // TEXT__X_FORTRAN,
612  'f77', // TEXT__X_FORTRAN,
613  'f90', // TEXT__X_FORTRAN,
614  'flv', // VIDEO__X_FLV,
615  'for', // TEXT__X_FORTRAN,
616  'g3', // IMAGE__G3FAX,
617  'gif', // IMAGE__GIF,
618  'gl', // VIDEO__GL,
619  'gan',
620  'gsd', // AUDIO__X_GSM,
621  'gsm', // AUDIO__X_GSM,
622  'gtar', // APPLICATION__X_GTAR,
623  'gz', // APPLICATION__X_GZIP,
624  'gzip', // APPLICATION__X_GZIP,
625  'htm', // TEXT__HTML,
626  'html', // TEXT__HTML,
627  'htmls', // TEXT__HTML,
628  'ibooks', // Apple IBook Format
629  'ico', // IMAGE__X_ICON,
630  'ics', // iCalendar, TEXT__CALENDAR
631  'ini', // scorm wbts
632  'java', // TEXT__X_JAVA_SOURCE,
633  'jbf', // scorm wbts
634  'jpeg', // IMAGE__PJPEG,
635  'jpg', // IMAGE__JPEG,
636  'js', // APPLICATION__X_JAVASCRIPT,
637  'jsf', // scorm wbts
638  'jso', // scorm wbts
639  'json', // APPLICATION__JSON
640  'latex', // APPLICATION__X_LATEX,
641  'lang', // lang files
642  'less', // less
643  'log', // TEXT__PLAIN,
644  'lsp', // APPLICATION__X_LISP,
645  'ltx', // APPLICATION__X_LATEX,
646  'm1v', // VIDEO__MPEG,
647  'm2a', // AUDIO__MPEG,
648  'm2v', // VIDEO__MPEG,
649  'm3u', // AUDIO__X_MPEQURL,
650  'm4a', // AUDIO__MP4,
651  'm4v', // VIDEO__MP4,
652  'markdown', // TEXT__MARKDOWN,
653  'm', // MATLAB
654  'mat', // MATLAB
655  'md', // TEXT__MARKDOWN,
656  'mdl', // Vensim files
657  'mdown', // TEXT__MARKDOWN,
658  'mid', // AUDIO__MIDI,
659  'min', // scorm articulate?
660  'midi', // AUDIO__MIDI,
661  'mobi', // APPLICATION__X_MOBI,
662  'mod', // AUDIO__MOD,
663  'mov', // VIDEO__QUICKTIME,
664  'movie', // VIDEO__X_SGI_MOVIE,
665  'mp2', // AUDIO__X_MPEG,
666  'mp3', // AUDIO__X_MPEG3,
667  'mp4', // VIDEO__MP4,
668  'mpa', // AUDIO__MPEG,
669  'mpeg', // VIDEO__MPEG,
670  'mpg', // AUDIO__MPEG,
671  'mph',
672  'mpga', // AUDIO__MPEG,
673  'mpp', // APPLICATION__VND_MS_PROJECT,
674  'mpt', // APPLICATION__X_PROJECT,
675  'mpv', // APPLICATION__X_PROJECT,
676  'mpx', // APPLICATION__X_PROJECT,
677  'mv', // VIDEO__X_SGI_MOVIE,
678  'mw',
679  'mv4', // VIDEO__MP4,
680  'nef', // IMAGE__X_NIKON_NEF,
681  'nif', // IMAGE__X_NIFF,
682  'niff', // IMAGE__X_NIFF,
683  'odt', // Open document text,
684  'ods', // Open document spreadsheet,
685  'odp', // Open document presentation,
686  'odg', // Open document graphics,
687  'odf', // Open document formula,
688  'oga', // AUDIO__OGG,
689  'ogg', // AUDIO__OGG,
690  'ogv', // VIDEO__OGG,
691  'old', // no real file extension, but used in mail/forum components,
692  'p', // TEXT__X_PASCAL,
693  'pas', // TEXT__PASCAL,
694  'pbm', // IMAGE__X_PORTABLE_BITMAP,
695  'pcl', // APPLICATION__VND_HP_PCL,
696  'pct', // IMAGE__X_PICT,
697  'pcx', // IMAGE__X_PCX,
698  'pdf', // APPLICATION__PDF,
699  'pgm', // IMAGE__X_PORTABLE_GRAYMAP,
700  'pic', // IMAGE__PICT,
701  'pict', // IMAGE__PICT,
702  'png', // IMAGE__PNG,
703  'pov', // MODEL__X_POV,
704  'project', // scorm wbts
705  'properties', // scorm wbts
706  'ppa', // APPLICATION__VND_MS_POWERPOINT,
707  'ppm', // IMAGE__X_PORTABLE_PIXMAP,
708  'pps', // APPLICATION__VND_MS_POWERPOINT,
709  'ppsx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_SLIDESHOW,
710  'ppt', // APPLICATION__POWERPOINT,
711  'pptx', // APPLICATION__VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_PRESENTATION,
712  'ppz', // APPLICATION__MSPOWERPOINT,
713  'ps', // APPLICATION__POSTSCRIPT,
714  'psd', // scorm wbts
715  'pwz', // APPLICATION__VND_MS_POWERPOINT,
716  'qt', // VIDEO__QUICKTIME,
717  'qtc', // VIDEO__X_QTC,
718  'qti', // IMAGE__X_QUICKTIME,
719  'qtif', // IMAGE__X_QUICKTIME,
720  'ra', // AUDIO__X_PN_REALAUDIO,
721  'ram', // AUDIO__X_PN_REALAUDIO,
722  'rast', // IMAGE__CMU_RASTER,
723  'rexx', // TEXT__X_SCRIPT_REXX,
724  'ris', // ris
725  'rf', // IMAGE__VND_RN_REALFLASH,
726  'rgb', // IMAGE__X_RGB,
727  'rm', // APPLICATION__VND_RN_REALMEDIA,
728  'rmi', // AUDIO__MID,
729  'rmm', // AUDIO__X_PN_REALAUDIO,
730  'rmp', // AUDIO__X_PN_REALAUDIO,
731  'rt', // TEXT__RICHTEXT,
732  'rtf', // TEXT__RICHTEXT,
733  'rtx', // TEXT__RICHTEXT,
734  'rv', // VIDEO__VND_RN_REALVIDEO,
735  's', // TEXT__X_ASM,
736  'sav', // SPSS
737  'sec', //
738  's3m', // AUDIO__S3M,
739  'sdml', // TEXT__PLAIN,
740  'sgm', // TEXT__SGML,
741  'sgml', // TEXT__SGML
742  'smi', // APPLICATION__SMIL,
743  'smil', // APPLICATION__SMIL,
744  'svg', // IMAGE__SVG_XML,
745  'swa', // scorm wbts
746  'swf', // APPLICATION__X_SHOCKWAVE_FLASH,
747  'swz', // scorm wbts
748  'tar', // application/x-tar
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  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getNewObjects()

static ilFileUtils::getNewObjects ( )
static

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

Referenced by ilObjFileGUI\handleFileUpload().

362  {
363  return self::$new_files;
364  }
+ Here is the caller graph for this function:

◆ getValidExtensions()

static ilFileUtils::getValidExtensions ( )
static
Returns
array valid file extensions

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

References $ilSetting.

Referenced by ilObjFileAccessSettingsGUI\initUploadSettingsForm().

533  {
534  global $ilSetting;
535 
536  // default white list
537  $whitelist = self::getDefaultValidExtensionWhiteList();
538 
539  // remove custom black list values
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]);
544  }
545  }
546 
547  // add custom white list values
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;
552  }
553  }
554 
555  return $whitelist;
556  }
global $ilSetting
Definition: privfeed.php:17
+ 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 789 of file class.ilFileUtils.php.

Referenced by ilFileVersionTableGUI\fillRow(), ilObjFile\getUploadFile(), ilObjFileGUI\handleFileUpload(), ilUtil\moveUploadedFile(), ilDAVServer\PUT(), assFileUpload\saveWorkingData(), ilFSStorageExercise\uploadFile(), ilExSubmission\uploadFile(), and ilBadgeImageTemplate\uploadImage().

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  }
Class to report exception.
+ Here is the caller graph for this function:

◆ lookupContentMimeType()

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

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

Referenced by ilQtiMatImageSecurity\determineMimeType().

501  {
502  $finfo = new finfo(FILEINFO_MIME);
503  return $finfo->buffer($content);
504  }
+ 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 510 of file class.ilFileUtils.php.

511  {
512  if(!file_exists($a_file) or !is_readable($a_file))
513  {
514  return false;
515  }
516 
517  return file_get_contents($a_file);
518  }

◆ 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

Author
Jan Hippchen
Version
1.6.9.07
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

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

References ilFileUtilsException\$BROKEN_FILE, ilFileUtilsException\$DOUBLETTES_FOUND, $file, ilFileUtilsException\$INFECTED_FILE, $lng, $ref_id, array, createObjects(), ilUtil\delDir(), ilUtil\moveUploadedFile(), recursive_dirscan(), ilUtil\unzip(), utf8_encode(), and ilUtil\virusHandling().

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

55  {
56 
57  global $lng;
58 
59  self::$new_files = array();
60 
61  $pathinfo = pathinfo($a_file);
62  $file = $pathinfo["basename"];
63 
64  // see 22727
65  if ($pathinfo["extension"] == "")
66  {
67  $file.= ".zip";
68  }
69 
70  // Copy zip-file to new directory, unzip and remove it
71  // TODO: check archive for broken file
72  //copy ($a_file, $a_directory . "/" . $file);
73  ilUtil::moveUploadedFile($a_file, $file, $a_directory . "/" . $file);
74  ilUtil::unzip($a_directory . "/" . $file);
75  unlink ($a_directory . "/" . $file);
76 //echo "-".$a_directory . "/" . $file."-";
77  // Stores filename and paths into $filearray to check for viruses
78  // Checks if filenames can be read, else -> throw exception and leave
79  ilFileUtils::recursive_dirscan($a_directory, $filearray);
80 
81  // if there are no files unziped (->broken file!)
82  if (empty($filearray)) {
83  throw new ilFileUtilsException($lng->txt("archive_broken"), ilFileUtilsException::$BROKEN_FILE);
84  }
85 
86  // virus handling
87  foreach ($filearray["file"] as $key => $value)
88  {
89  // remove "invisible" files
90  if(substr($value, 0, 1) == "." || stristr($filearray["path"][$key], "/__MACOSX/"))
91  {
92  unlink($filearray["path"][$key].$value);
93  unset($filearray["path"][$key]);
94  unset($filearray["file"][$key]);
95  continue;
96  }
97 
98  $vir = ilUtil::virusHandling($filearray["path"][$key], $value);
99  if (!$vir[0])
100  {
101  // Unlink file and throw exception
102  unlink($filearray[path][$key]);
103  throw new ilFileUtilsException($lng->txt("file_is_infected")."<br />".$vir[1], ilFileUtilsException::$INFECTED_FILE);
104  break;
105  }
106  else
107  {
108  if ($vir[1] != "")
109  {
111  break;
112  }
113  }
114  }
115 
116  // If archive is to be used "flat"
117  if (!$structure)
118  {
119  foreach (array_count_values($filearray["file"]) as $key => $value)
120  {
121  // Archive contains same filenames in different directories
122  if ($value != "1")
123  {
124  $doublettes .= " '" . ilFileUtils::utf8_encode($key) . "'";
125 
126  }
127  }
128  if (isset($doublettes))
129  {
130  throw new ilFileUtilsException($lng->txt("exc_upload_error") . "<br />" . $lng->txt("zip_structure_error") . $doublettes ,
132  }
133  }
134  else
135  {
136  $mac_dir = $a_directory."/__MACOSX";
137  if(file_exists($mac_dir))
138  {
139  ilUtil::delDir($mac_dir);
140  }
141  }
142 
143  // Everything fine since we got here; so we can store files and folders into the system (if ref_id is given)
144  if ($ref_id != null)
145  {
146  ilFileUtils::createObjects ($a_directory, $structure, $ref_id, $containerType, $tree, $access_handler);
147  }
148 
149  }
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 createObjects($dir, $structure, $ref_id, $containerType, $tree=null, $access_handler=null)
Recursively scans a given directory and creates file and folder/category objects. ...
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
Create styles array
The data for the language used.
static utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
$ref_id
Definition: sahs_server.php:39
global $lng
Definition: privfeed.php:17
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
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.

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

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

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

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

160  {
161  global $lng;
162 
163  $dirlist = opendir($dir);
164  while (false !== ($file = readdir ($dirlist)))
165  {
166  if (!is_file($dir . "/" . $file) && !is_dir($dir . "/" . $file))
167  {
168  throw new ilFileUtilsException($lng->txt("filenames_not_supported"), ilFileUtilsException::$BROKEN_FILE);
169  }
170 
171  if ($file != '.' && $file != '..')
172  {
173  $newpath = $dir.'/'.$file;
174  $level = explode('/',$newpath);
175  if (is_dir($newpath))
176  {
177  ilFileUtils::recursive_dirscan($newpath, $arr);
178  }
179  else
180  {
181  $arr["path"][] = $dir . "/";
182  $arr["file"][] = end($level);
183  }
184  }
185  }
186  closedir($dirlist);
187  }
global $lng
Definition: privfeed.php:17
static recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
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 823 of file class.ilFileUtils.php.

Referenced by ilAssFileUploadUploadsExporter\createFileUploadCollectionZipFile(), ilFileDataForum\getForumPath(), assFlashQuestion\moveAppletIfExists(), ilObjSCORMLearningModuleGUI\newModuleVersionUpload(), ilFileSystemGUI\renameFile(), ilFileXMLParser\setFileContents(), ilObjFile\storeUnzipedFile(), and ilObjSAHSLearningModuleGUI\uploadObject().

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  }
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.

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

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

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

374  {
375 
376  // From http://w3.org/International/questions/qa-forms-utf-8.html
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);
387  }
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 40 of file class.ilFileUtils.php.


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