ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilFileUtils Class Reference

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

+ Collaboration diagram for ilFileUtils:

Public Member Functions

 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...
 
 recursive_dirscan ($dir, &$arr)
 Recursively scans a given directory and writes path and filename into referenced array. More...
 
 createObjects ($dir, $structure, $ref_id, $containerType, $tree=null, $access_handler=null)
 Recursively scans a given directory and creates file and folder/category objects. More...
 
 createContainer ($name, $ref_id, $containerType, $tree=null, $access_handler=null)
 Creates and inserts container object (folder/category) into tree. More...
 
 utf8_encode ($string)
 utf8-encodes string if it is not a valid utf8-string. More...
 
 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 createFile ($filename, $path, $ref_id, $tree=null, $access_handler=null)
 Creates and inserts file object into tree. More...
 
static getNewObjects ()
 
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 527 of file class.ilFileUtils.php.

Referenced by ilFileXMLParser\handlerEndTag().

528  {
529  return self::lookupFileMimeType($a_file);
530  }
+ Here is the caller graph for this function:

◆ createContainer()

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

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

References $lng, and $ref_id.

Referenced by createObjects().

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

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

Referenced by createObjects().

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

◆ createObjects()

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

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

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

Referenced by processZipFile().

207  {
208  $dirlist = opendir($dir);
209 
210  while (false !== ($file = readdir ($dirlist)))
211  {
212  if (!is_file($dir . "/" . $file) && !is_dir($dir . "/" . $file))
213  {
214  throw new ilFileUtilsException($lng->txt("filenames_not_supported") , ilFileUtilsException::$BROKEN_FILE);
215  }
216  if ($file != '.' && $file != '..')
217  {
218  $newpath = $dir.'/'.$file;
219  $level = explode('/',$newpath);
220  if (is_dir($newpath))
221  {
222  if ($structure)
223  {
224  $new_ref_id = ilFileUtils::createContainer(ilFileUtils::utf8_encode($file), $ref_id, $containerType, $tree, $access_handler);
225  ilFileUtils::createObjects($newpath, $structure, $new_ref_id, $containerType, $tree, $access_handler);
226  }
227  else
228  {
229  ilFileUtils::createObjects($newpath, $structure, $ref_id, $containerType, $tree, $access_handler);
230  }
231  }
232  else
233  {
234  ilFileUtils::createFile (end($level), $dir, $ref_id, $tree, $access_handler);
235  }
236  }
237  }
238  closedir($dirlist);
239  }
print $file
static createFile($filename, $path, $ref_id, $tree=null, $access_handler=null)
Creates and inserts file object into tree.
createContainer($name, $ref_id, $containerType, $tree=null, $access_handler=null)
Creates and inserts container object (folder/category) into tree.
utf8_encode($string)
utf8-encodes string if it is not a valid utf8-string.
createObjects($dir, $structure, $ref_id, $containerType, $tree=null, $access_handler=null)
Recursively scans a given directory and creates file and folder/category objects. ...
$ref_id
Definition: sahs_server.php:39
global $lng
Definition: privfeed.php:40
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 398 of file class.ilFileUtils.php.

Referenced by ilFileXMLParser\handlerEndTag().

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

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

◆ 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  if ((!file_exists ($out) && !is_writable (dirname ($out)) || (file_exists($out) && !is_writable($out)) ))
483  return false;
484 
485  $in_file = gzopen ($in, "rb");
486  $out_file = fopen ($out, "wb");
487 
488  while (!gzeof ($in_file)) {
489  $buffer = gzread ($in_file, 4096);
490  fwrite ($out_file, $buffer, 4096);
491  }
492 
493  gzclose ($in_file);
494  fclose ($out_file);
495 
496  return true;
497  }
+ 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 447 of file class.ilFileUtils.php.

References $in, and $out.

448  {
449  if (!file_exists ($in) || !is_readable ($in))
450  return false;
451  if ((!file_exists ($out) && !is_writable (dirname ($out)) || (file_exists($out) && !is_writable($out)) ))
452  return false;
453 
454  $in_file = fopen ($in, "rb");
455  if (!$out_file = gzopen ($out, "wb".$param)) {
456  return false;
457  }
458 
459  while (!feof ($in_file)) {
460  $buffer = fgets ($in_file, 4096);
461  gzwrite ($out_file, $buffer, 4096);
462  }
463 
464  fclose ($in_file);
465  gzclose ($out_file);
466 
467  return true;
468  }

◆ getDefaultValidExtensionWhiteList()

static ilFileUtils::getDefaultValidExtensionWhiteList ( )
static

Valid extensions.

Returns
array valid file extensions

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

Referenced by ilObjFileAccessSettingsGUI\initUploadSettingsForm().

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

◆ getNewObjects()

static ilFileUtils::getNewObjects ( )
static

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

Referenced by ilObjFileGUI\handleFileUpload().

365  {
366  return self::$new_files;
367  }
+ Here is the caller graph for this function:

◆ getValidExtensions()

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

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

References $ilSetting.

Referenced by ilObjFileAccessSettingsGUI\initUploadSettingsForm().

536  {
537  global $ilSetting;
538 
539  // default white list
540  $whitelist = self::getDefaultValidExtensionWhiteList();
541 
542  // remove custom black list values
543  foreach (explode(",", $ilSetting->get("suffix_repl_additional")) as $custom_black) {
544  $custom_black = trim(strtolower($custom_black));
545  if (($key = array_search($custom_black, $whitelist)) !== false) {
546  unset($whitelist[$key]);
547  }
548  }
549 
550  // add custom white list values
551  foreach (explode(",", $ilSetting->get("suffix_custom_white_list")) as $custom_white) {
552  $custom_white = trim(strtolower($custom_white));
553  if (!in_array($custom_white, $whitelist)) {
554  $whitelist[] = $custom_white;
555  }
556  }
557 
558  return $whitelist;
559  }
global $ilSetting
Definition: privfeed.php:40
+ 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 ilObjFile\getUploadFile(), ilObjFileGUI\handleFileUpload(), ilUtil\moveUploadedFile(), ilDAVServer\PUT(), ilFSStorageExercise\uploadFile(), and ilExSubmission\uploadFile().

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

Referenced by ilQtiMatImageSecurity\determineMimeType().

504  {
505  $finfo = new finfo(FILEINFO_MIME);
506  return $finfo->buffer($content);
507  }
+ 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 513 of file class.ilFileUtils.php.

514  {
515  if(!file_exists($a_file) or !is_readable($a_file))
516  {
517  return false;
518  }
519 
520  return self::lookupContentMimeType(file_get_contents($a_file));
521  }

◆ processZipFile()

ilFileUtils::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

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

ilFileUtils::recursive_dirscan (   $dir,
$arr 
)

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 162 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().

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

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()

ilFileUtils::utf8_encode (   $string)

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

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

377  {
378 
379  // From http://w3.org/International/questions/qa-forms-utf-8.html
380  return (preg_match('%^(?:
381  [\x09\x0A\x0D\x20-\x7E] # ASCII
382  | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
383  | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
384  | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
385  | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
386  | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
387  | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
388  | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
389  )*$%xs', $string))? $string : utf8_encode($string);
390  }
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: