ILIAS  release_8 Revision v8.24
ilFileUtils Class Reference

Class ilFileUtils. More...

+ Collaboration diagram for ilFileUtils:

Static Public Member Functions

static processZipFile (string $a_directory, string $a_file, bool $structure)
 
static recursive_dirscan (string $dir, array &$arr)
 Recursively scans a given directory and writes path and filename into referenced array. More...
 
static utf8_encode (string $string)
 utf8-encodes string if it is not a valid utf8-string. More...
 
static getValidFilename (string $a_filename)
 
static rename (string $a_source, string $a_target)
 
static rCopy (string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
 Copies content of a directory $a_sdir recursively to a directory $a_tdir. More...
 
static makeDirParents (string $a_dir)
 Create a new directory and all parent directories. More...
 
static getDataDir ()
 get data directory (outside webspace) More...
 
static dirsize (string $directory)
 get size of a directory or a file. More...
 
static makeDir (string $a_dir)
 creates a new directory and inherits all filesystem permissions of the parent directory You may pass only the name of your new directory or with the entire path or relative path information. More...
 
static moveUploadedFile (string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
 move uploaded file More...
 
static zip (string $a_dir, string $a_file, bool $compress_content=false)
 zips given directory/file into given zip.file More...
 
static delDir (string $a_dir, bool $a_clean_only=false)
 removes a dir and all its content (subdirs and files) recursively More...
 
static getSafeFilename (string $a_initial_filename)
 
static getDir (string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
 get directory More...
 
static getWebspaceDir (string $mode="filesystem")
 get webspace directory More...
 
static createDirectory (string $a_dir, int $a_mod=0755)
 create directory More...
 
static getFileSizeInfo ()
 
static getASCIIFilename (string $a_filename)
 
static ilTempnam (?string $a_temp_path=null)
 Returns a unique and non existing Path for e temporary file or directory. More...
 
static unzip (string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
 
static renameExecutables (string $a_dir)
 
static rRenameSuffix (string $a_dir, string $a_old_suffix, string $a_new_suffix)
 Renames all files with certain suffix and gives them a new suffix. More...
 
static removeTrailingPathSeparators (string $path)
 
static getUploadSizeLimitBytes ()
 
static _sanitizeFilemame (string $a_filename)
 

Static Protected Member Functions

static sanitateTargetPath (string $a_target)
 

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.

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

Member Function Documentation

◆ _sanitizeFilemame()

static ilFileUtils::_sanitizeFilemame ( string  $a_filename)
static

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

1087 : string
1088 {
1089 return strip_tags(ilUtil::stripSlashes($a_filename));
1090 }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")

References ilUtil\stripSlashes().

Referenced by ilSoapUtils\distributeMails(), ilFileDataMail\storeAsAttachment(), ilFileDataMail\storeUploadedFile(), ilFileDataForum\storeUploadedFile(), and ilFileDataForumDrafts\storeUploadedFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createDirectory()

static ilFileUtils::createDirectory ( string  $a_dir,
int  $a_mod = 0755 
)
static

create directory

Parameters
string$a_dir
int$a_mod
Deprecated:
in favour of Filesystem::createDir() located at the filesystem service.
See also
\ILIAS\Filesystem\Filesystem::createDir()

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

794 : void
795 {
796 ilFileUtils::makeDir($a_dir);
797 }
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...

References makeDir().

Referenced by ilExerciseManagementCollectFilesJob\createSubmissionsDirectory(), ilMediaItem\createWorkDirectory(), ilTempnam(), and assQuestion\moveUploadedMediaFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delDir()

static ilFileUtils::delDir ( string  $a_dir,
bool  $a_clean_only = false 
)
static

removes a dir and all its content (subdirs and files) recursively

@access public

Parameters
string$a_dirdir to delete
bool$a_clean_only
Author
Unknown flexe.nosp@m.r@cu.nosp@m.tephp.nosp@m..com (source: http://www.php.net/rmdir)
Deprecated:
in favour of Filesystem::deleteDir() located at the filesystem service.
See also
\ILIAS\Filesystem\Filesystem::deleteDir()

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

632 : void
633 {
634 if (!is_dir($a_dir) || is_int(strpos($a_dir, ".."))) {
635 return;
636 }
637
638 $current_dir = opendir($a_dir);
639
640 $files = [];
641
642 // this extra loop has been necessary because of a strange bug
643 // at least on MacOS X. A looped readdir() didn't work
644 // correctly with larger directories
645 // when an unlink happened inside the loop. Getting all files
646 // into the memory first solved the problem.
647 while ($entryname = readdir($current_dir)) {
648 $files[] = $entryname;
649 }
650
651 foreach ($files as $file) {
652 if (is_dir(
653 $a_dir . "/" . $file
654 ) and ($file != "." and $file != "..")) {
655 ilFileUtils::delDir($a_dir . "/" . $file);
656 } elseif ($file != "." and $file != "..") {
657 unlink($a_dir . "/" . $file);
658 }
659 }
660
661 closedir($current_dir);
662 if (!$a_clean_only) {
663 @rmdir($a_dir);
664 }
665 }
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively

References delDir().

Referenced by ilObjTest\_createImportDirectory(), assMatchingQuestion\afterSyncWithOriginal(), assSingleChoice\afterSyncWithOriginal(), ilScorm2004DataSet\afterXmlRecordWriting(), ilUserDataSet\afterXmlRecordWriting(), ILIAS\Wiki\Export\WikiHtmlExport\buildExportFile(), ilSurveyExport\buildExportFileXML(), ilObjStyleSheet\cleanExportDirectory(), assOrderingQuestion\cleanImagefiles(), assLongMenu\clearFolder(), ilExAssignment\clearMultiFeedbackDirectory(), ilObjMediaObject\clearMultiSrtDirectory(), ilMobMultiSrtUpload\clearMultiSrtDirectory(), ilTestExportGUI\createTestArchiveExport(), delDir(), ilCertificateUtilHelper\delDir(), ilFileDataForumDrafts\delete(), ilObjFileBasedLM\delete(), ilObjSAHSLearningModule\delete(), ilObjSurvey\delete(), ilBadgeImageTemplate\delete(), ilExportGUI\delete(), ilObjMediaObject\delete(), SurveyQuestion\delete(), assQuestion\delete(), ilObjSurveyQuestionPool\deleteAllData(), ilFileDataMail\deleteAttachmentDirectory(), ilFileDataCourse\deleteDirectory(), ILIAS\Mail\Cron\ExpiredOrOrphanedMails\MailDeletionHandler\deleteDirectory(), ilObjSurveyQuestionPoolGUI\deleteExportFileObject(), ilFileSystemGUI\deleteFile(), ilExAssignment\deleteGlobalFeedbackFile(), ilObjQuestionPool\deleteQuestionpool(), ilBadge\deleteStaticFiles(), assQuestion\deleteSuggestedSolutions(), ilObjSurvey\deleteSurveyRecord(), ilObjTest\deleteTest(), ilFileDataForum\deliverZipFile(), ilFileDataForumDrafts\deliverZipFile(), ilObjCmiXapi\doDelete(), ilObjFileBasedLMGUI\exportHTML(), ilExportContainer\exportObject(), ilObjUser\exportPersonalData(), ilExAssignment\handleGlobalFeedbackFileUpload(), ilExcCriteriaFile\importFromPeerReviewForm(), ilObjSurveyQuestionPool\importObject(), ilObjTestGUI\importVerifiedFileObject(), ilObjQuestionPoolGUI\importVerifiedFileObject(), ILIAS\Blog\Export\BlogHtmlExport\initDirectories(), ILIAS\Glossary\Export\GlossaryHtmlExport\initDirectories(), ILIAS\LearningModule\Export\LMHtmlExport\initDirectories(), ILIAS\Portfolio\Export\PortfolioHtmlExport\initDirectories(), ILIAS\Notes\Export\NotesHtmlExport\initDirectories(), assKprimChoice\removeAnswerImage(), ilAssFileUploadUploadsExporter\removeFileUploadCollection(), ilObjTest\removeTestResultsByActiveIds(), ILIAS\MediaCast\BackgroundTasks\DownloadAllZipJob\run(), ilZipJob\run(), ilCalendarZipJob\run(), ilOrgUnitExporter\sendAndCreateSimpleExportFile(), assMultipleChoice\syncImages(), assSingleChoice\syncImages(), ilExAssignment\uploadMultiFeedbackFile(), ilObjSAHSLearningModuleGUI\uploadObject(), ilObjQuestionPoolGUI\uploadQplObject(), ilObjTestGUI\uploadTst(), ilUserCertificateZip\zipCertificatesInArchiveDirectory(), ILIAS\Blog\Export\BlogHtmlExport\zipPackage(), ILIAS\Glossary\Export\GlossaryHtmlExport\zipPackage(), ILIAS\LearningModule\Export\LMHtmlExport\zipPackage(), ILIAS\Portfolio\Export\PortfolioHtmlExport\zipPackage(), and ILIAS\Notes\Export\NotesHtmlExport\zipPackage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dirsize()

static ilFileUtils::dirsize ( string  $directory)
static

get size of a directory or a file.

Parameters
stringpath to a directory or a file
Returns
integer. Returns -1, if the directory does not exist.

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

371 : int
372 {
373 $size = 0;
374 if (!is_dir($directory)) {
375 // dirsize of non-existing directory
376 $size = @filesize($directory);
377 return ($size === false) ? -1 : $size;
378 }
379 if ($DIR = opendir($directory)) {
380 while (($dirfile = readdir($DIR)) !== false) {
381 if (is_link(
382 $directory . DIRECTORY_SEPARATOR . $dirfile
383 ) || $dirfile == '.' || $dirfile == '..') {
384 continue;
385 }
386 if (is_file($directory . DIRECTORY_SEPARATOR . $dirfile)) {
387 $size += filesize(
388 $directory . DIRECTORY_SEPARATOR . $dirfile
389 );
390 } elseif (is_dir($directory . DIRECTORY_SEPARATOR . $dirfile)) {
391 $dirSize = ilFileUtils::dirsize(
392 $directory . DIRECTORY_SEPARATOR . $dirfile
393 );
394 if ($dirSize >= 0) {
395 $size += $dirSize;
396 } else {
397 return -1;
398 }
399 }
400 }
401 closedir($DIR);
402 }
403 return $size;
404 }
static dirsize(string $directory)
get size of a directory or a file.

References dirsize().

Referenced by ilObjFileBasedLMAccess\_lookupDiskUsage(), ilObjMediaCastAccess\_lookupDiskUsage(), ilObjSAHSLearningModuleAccess\_lookupDiskUsage(), dirsize(), and ilPortfolioTemplatePage\getPageDiskSize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getASCIIFilename()

static ilFileUtils::getASCIIFilename ( string  $a_filename)
static
Deprecated:

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

812 : string
813 {
814 global $DIC;
815 $policy = new ilFileServicesPolicy($DIC->fileServiceSettings());
816 return $policy->ascii($a_filename);
817 }
Class ilFileServicesPolicy.
global $DIC
Definition: feed.php:28

References $DIC.

Referenced by ilTestExport\aggregatedResultsToCSV(), ilTestExport\aggregatedResultsToExcel(), ILIAS\Wiki\Export\WikiHtmlExport\buildExportFile(), ilExerciseManagementCollectFilesJob\collectAssignmentData(), ilDownloadFilesBackgroundTask\collectFiles(), ilObjTest\deliverPDFfromFO(), ilSurveyParticipantsGUI\exportAllCodesObject(), ilTestEvaluationGUI\exportCertificate(), ilSurveyParticipantsGUI\exportCodesObject(), ilSurveyEvaluationGUI\exportEvaluationUser(), ilObjExercise\exportGradesExcel(), ilTestExport\exportToCSV(), ilTestExport\exportToExcel(), ilObjWorkspaceFolderGUI\getBucketTitle(), ilContainerGUI\getBucketTitle(), ilExSubmission\getDirectoryNameFromUserData(), ilAssFileUploadUploadsExporter\getDispoZipFileName(), ilCollectFilesJob\getFileDirs(), ilTestParticipantData\getFileSystemCompliantFullnameByActiveId(), ilVerificationObject\getOfflineFilename(), ilObjTest\getTitleFilenameCompliant(), assQuestion\getTitleFilenameCompliant(), ilAssFileUploadUploadsExporter\initFilenames(), ilDclMobRecordFieldModel\parseValue(), ilCollectFilesJob\recurseFolder(), ilDownloadSubmissionsBackgroundTask\run(), ILIAS\MediaCast\BackgroundTasks\DownloadAllBackgroundTask\run(), ilDownloadWorkspaceFolderBackgroundTask\run(), ilDownloadFilesBackgroundTask\run(), ilDownloadContainerFilesBackgroundTask\run(), ilQtiMatImageSecurity\sanitizeLabel(), and ilExAssignment\sendMultiFeedbackStructureFile().

+ Here is the caller graph for this function:

◆ getDataDir()

static ilFileUtils::getDataDir ( )
static

get data directory (outside webspace)

Deprecated:
in favour of the filesystem service which should be used to operate on the storage directory.
See also
\ILIAS\DI\Containerfilesystem()
\ILIAS\Filesystem\Filesystems::storage()

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

358 : string
359 {
360 return CLIENT_DATA_DIR;
361 }
const CLIENT_DATA_DIR
Definition: constants.php:46

References CLIENT_DATA_DIR.

Referenced by ilAdvancedMDRecordImportFiles\__construct(), ilAdvancedMDRecordExportFiles\__construct(), ilObjTest\_createImportDirectory(), ilObjQuestionPool\_createImportDirectory(), ilHtmlPurifierAbstractLibWrapper\_getCacheDirectory(), ilObjCategoryGUI\_getImportDir(), assLongMenu\buildFolderName(), ilObjStyleSheet\cleanExportDirectory(), ilDclPropertyFormGUI\cleanupTempFiles(), ilSimpleSAMLphpConfigTemplateHandler\copy(), ilChatroomConfigFileHandler\createDataDirIfNotExists(), ilObjSurvey\createExportDirectory(), ilObjSurveyQuestionPool\createExportDirectory(), ilObjTest\createExportDirectory(), ilObjQuestionPool\createExportDirectory(), ilObjStyleSheet\createExportDirectory(), ilObjUserFolder\createExportDirectory(), ilObjGlossary\createImportDirectory(), ilObjContentObject\createImportDirectory(), ilObjSurvey\createImportDirectory(), ilObjSurveyQuestionPool\createImportDirectory(), ilObjStyleSheet\createImportDirectory(), ilMediaItem\createWorkDirectory(), ilObjSurveyQuestionPool\deleteAllData(), ilObjQuestionPool\deleteQuestionpool(), ilObjSurvey\deleteSurveyRecord(), ilObjTest\deleteTest(), ilImportDirectory\getAbsolutePath(), ilExportImportDirectory\getAbsolutePathForHash(), ilSamlAuthFactory\getConfigDirectory(), ilObjContentObject\getDataDirectory(), ilObjQuestionPool\getExportDirectory(), ilObjSurvey\getExportDirectory(), ilObjSurveyQuestionPool\getExportDirectory(), ilObjTest\getExportDirectory(), ilObjUserFolder\getExportDirectory(), ilObjContentObject\getExportDirectory(), ilMediaImageUtil\getImageSize(), ilObjGlossary\getImportDirectory(), ilObjContentObject\getImportDirectory(), ilObjSurvey\getImportDirectory(), ilObjSurveyQuestionPool\getImportDirectory(), ilUserPasswordManager\getInstance(), ilFSStorageMail\getRelativePathExMailDirectory(), ilLMMultiSrt\getUploadDir(), ilMepMultiSrt\getUploadDir(), ilMediaItem\getWorkDirectory(), ilObjUserFolderGUI\handleUploadedFiles(), ilTempnam(), ilObjUserFolderGUI\importUserRoleAssignmentObject(), ilObjUserFolderGUI\importUsersObject(), ilTestQuestionPoolExporter\lookupExportDirectory(), ilXmlExporter\lookupExportDirectory(), ilDclPropertyFormGUI\rebuildTempFileByHash(), and ilPropertyFormGUI\rebuildUploadedFiles().

+ Here is the caller graph for this function:

◆ getDir()

static ilFileUtils::getDir ( string  $a_dir,
bool  $a_rec = false,
?string  $a_sub_dir = "" 
)
static

get directory

Parameters
string$a_dir
bool$a_rec
string | null$a_sub_dir
Returns
array
Deprecated:
in favour of Filesystem::listContents() located at the filesystem service.
See also
\ILIAS\Filesystem\Filesystem::listContents()

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

717 : array {
718 $current_dir = opendir($a_dir . $a_sub_dir);
719
720 $dirs = [];
721 $files = [];
722 $subitems = [];
723 while ($entry = readdir($current_dir)) {
724 if (is_dir($a_dir . "/" . $entry)) {
725 $dirs[$entry] = ["type" => "dir",
726 "entry" => $entry,
727 "subdir" => $a_sub_dir
728 ];
729 if ($a_rec && $entry != "." && $entry != "..") {
731 $a_dir,
732 true,
733 $a_sub_dir . "/" . $entry
734 );
735 $subitems = array_merge($subitems, $si);
736 }
737 } else {
738 if ($entry != "." && $entry != "..") {
739 $size = filesize($a_dir . $a_sub_dir . "/" . $entry);
740 $files[$entry] = ["type" => "file",
741 "entry" => $entry,
742 "size" => $size,
743 "subdir" => $a_sub_dir
744 ];
745 }
746 }
747 }
748 ksort($dirs);
749 ksort($files);
750
751 return array_merge($dirs, $files, $subitems);
752 }
static getDir(string $a_dir, bool $a_rec=false, ?string $a_sub_dir="")
get directory

References getDir().

Referenced by assOrderingQuestion\cleanImagefiles(), ilFileDataMail\getAttachmentPathAndFilenameByMd5Hash(), getDir(), ilCertificateUtilHelper\getDir(), ilFileDataForum\getFileDataByMD5Filename(), ilFileDataForumDrafts\getFileDataByMD5Filename(), ilFileSystemGUI\getFileList(), ilAdvancedMDRecordExportFiles\getFiles(), ilUploadDirFilesTableGUI\getFiles(), ilExAssignment\getMultiFeedbackFiles(), ilObjMediaObject\getMultiSrtFiles(), ilMobMultiSrtUpload\getMultiSrtFiles(), ilObjUser\getPersonalDataExportFile(), ilObjMediaObject\getSrtFiles(), ilFileDataForum\unlinkFilesByMD5Filenames(), ilFileDataForumDrafts\unlinkFilesByMD5Filenames(), ilFileSystemGUI\unzipFile(), and ilExAssignment\uploadMultiFeedbackFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFileSizeInfo()

static ilFileUtils::getFileSizeInfo ( )
static

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

799 : string
800 {
801 global $DIC;
802 $size = new DataSize(self::getUploadSizeLimitBytes(), DataSize::MB);
803 $max_filesize = $size->__toString();
804 $lng = $DIC->language();
805
806 return $lng->txt("file_notice") . " $max_filesize.";
807 }
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:31
$lng

References $DIC, and $lng.

Referenced by ilTinyMCE\addCustomRTESupport(), ilImageWizardInputGUI\insert(), ilMatchingWizardInputGUI\insert(), ilMultipleChoiceWizardInputGUI\insert(), ilSingleChoiceWizardInputGUI\insert(), ilAssMultipleChoiceCorrectionsInputGUI\insert(), ilAssSingleChoiceCorrectionsInputGUI\insert(), and ilMultipleImagesInputGUI\render().

+ Here is the caller graph for this function:

◆ getSafeFilename()

static ilFileUtils::getSafeFilename ( string  $a_initial_filename)
static

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

667 : string
668 {
669 $file_peaces = explode('.', $a_initial_filename);
670
671 $file_extension = array_pop($file_peaces);
672
673 if (SUFFIX_REPL_ADDITIONAL) {
674 $string_extensions = SUFFIX_REPL_DEFAULT . "," . SUFFIX_REPL_ADDITIONAL;
675 } else {
676 $string_extensions = SUFFIX_REPL_DEFAULT;
677 }
678
679 $sufixes = explode(",", $string_extensions);
680
681 if (in_array($file_extension, $sufixes)) {
682 $file_extension = "sec";
683 }
684
685 $file_peaces[] = $file_extension;
686
687 $safe_filename = "";
688 foreach ($file_peaces as $piece) {
689 $safe_filename .= "$piece";
690 if ($piece != end($file_peaces)) {
691 $safe_filename .= ".";
692 }
693 }
694
695 return $safe_filename;
696 }

Referenced by ilExAssignment\instructionFileInsertOrder().

+ Here is the caller graph for this function:

◆ getUploadSizeLimitBytes()

static ilFileUtils::getUploadSizeLimitBytes ( )
static
Deprecated:
should use DataSize instead

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

1047 : string
1048 {
1049 $convertPhpIniSizeValueToBytes = function ($phpIniSizeValue) {
1050 if (is_numeric($phpIniSizeValue)) {
1051 return $phpIniSizeValue;
1052 }
1053
1054 $suffix = substr($phpIniSizeValue, -1);
1055 $value = substr($phpIniSizeValue, 0, -1);
1056
1057 switch (strtoupper($suffix)) {
1058 case 'P':
1059 $value *= 1024;
1060 // no break
1061 case 'T':
1062 $value *= 1024;
1063 // no break
1064 case 'G':
1065 $value *= 1024;
1066 // no break
1067 case 'M':
1068 $value *= 1024;
1069 // no break
1070 case 'K':
1071 $value *= 1024;
1072 break;
1073 }
1074
1075 return $value;
1076 };
1077
1078
1079 $uploadSizeLimitBytes = min(
1080 $convertPhpIniSizeValueToBytes(ini_get('post_max_size')),
1081 $convertPhpIniSizeValueToBytes(ini_get('upload_max_filesize'))
1082 );
1083
1084 return $uploadSizeLimitBytes;
1085 }

Referenced by ilDAVContainer\createFile(), InitUIFramework\init(), ilFileVersionFormGUI\initForm(), ilObjFileGUI\initUploadForm(), ilDAVFile\put(), and ILIAS\FileUpload\FileUploadImpl\uploadSizeLimit().

+ Here is the caller graph for this function:

◆ getValidFilename()

static ilFileUtils::getValidFilename ( string  $a_filename)
static

◆ getWebspaceDir()

static ilFileUtils::getWebspaceDir ( string  $mode = "filesystem")
static

get webspace directory

Parameters
string$modeuse "filesystem" for filesystem operations and "output" for output operations, e.g. images
Returns
string
Deprecated:
in favour of the filesystem service which should be used for operations on the web dir.
See also
\ILIAS\DI\Containerfilesystem()
Filesystems::web()

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

769 : string
770 {
771 if ($mode === "filesystem") {
772 return "./" . ILIAS_WEB_DIR . "/" . CLIENT_ID;
773 } else {
774 if (defined("ILIAS_MODULE")) {
775 return "../" . ILIAS_WEB_DIR . "/" . CLIENT_ID;
776 } else {
777 return "./" . ILIAS_WEB_DIR . "/" . CLIENT_ID;
778 }
779 }
780 }
const CLIENT_ID
Definition: constants.php:41
const ILIAS_WEB_DIR
Definition: constants.php:45

References CLIENT_ID, and ILIAS_WEB_DIR.

Referenced by ilObjFileBasedLMAccess\_determineStartUrl(), ilContainer\_getContainerDirectory(), ilObjStyleSheet\_getImagesDirectory(), ilChatroomSmilies\_getSmileyDir(), ilChatroomAdminSmileyGUI\_getSmileyDir(), ilObjFileBasedLMAccess\_lookupDiskUsage(), ilObjSAHSLearningModuleAccess\_lookupDiskUsage(), ilTestPlayerAbstractGUI\archiveParticipantSubmission(), ilCmiXapiLaunchGUI\buildLaunchLink(), ilTestSubmissionReviewGUI\buildPdfFilename(), ilQuestionPageParser\copyMobFiles(), ilContainer\createContainerDirectory(), ilObjSAHSLearningModule\createDataDirectory(), ilObjectCustomIconImpl\createFromImportDir(), ilObjectTileImage\createFromImportDir(), ilObjStyleSheet\delete(), ilPublicUserProfileGUI\deliverVCard(), ilPageObjectGUI\displayMedia(), ilObjCmiXapi\doCloneObject(), ilObjCmiXapi\doDelete(), ilCOPageHTMLExport\exportQuestionFiles(), ilStudyProgrammeTypeCustomIconsFormGUI\fillForm(), ilStudyProgrammeTypeTableGUI\fillRow(), ilLTIConsumeProviderIcon\getAbsoluteFilePath(), ilCmiXapiContentUploadImporter\getAbsoluteObjectDirectory(), ilDidacticTemplateIconHandler\getAbsolutePath(), ilBadgeHandler\getBasePath(), ilObjMediaObject\getDataDirectory(), ilObjSAHSLearningModule\getDataDirectory(), ilObjFileBasedLM\getDataDirectory(), ilPublicUserProfileGUI\getEmbeddable(), ilObjectTileImage\getFullPath(), ilObjectCustomIconImpl\getFullPath(), ilOrgUnitType\getIconPath(), ilOpenIdConnectSettings\getImageFilePath(), ilFileDataCourse\getOnlineLink(), ilUserXMLWriter\getPictureValue(), ilFSStorageMail\getRelativePathExMailDirectory(), ilLMPresentationGUI\ilMedia(), ilUserAvatarResolver\init(), ilUserCertificateGUI\listCertificates(), ilGlossaryPresentationGUI\media(), ilCmiXapiImporter\prepareLocalSourceStorage(), ilObjUserGUI\removeUserPictureObject(), ilCmiXapiContentUploadImporter\sanitizeObjectDirectory(), ilObjMediaPoolGUI\showMedia(), ilPageObjectGUI\showMediaFullscreen(), ilPageObjectGUI\showPage(), ilLMPresentationGUI\showPrintView(), ilPersonalProfileGUI\uploadUserPicture(), ilObjUserGUI\uploadUserPictureObject(), and ilObjStyleSheet\writeCSSFile().

+ Here is the caller graph for this function:

◆ ilTempnam()

static ilFileUtils::ilTempnam ( ?string  $a_temp_path = null)
static

Returns a unique and non existing Path for e temporary file or directory.

Parameters
string | null$a_temp_path
Returns
string

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

826 : string
827 {
828 if ($a_temp_path === null) {
829 $temp_path = ilFileUtils::getDataDir() . "/temp";
830 } else {
831 $temp_path = $a_temp_path;
832 }
833
834 if (!is_dir($temp_path)) {
836 }
837 $temp_name = $temp_path . "/" . uniqid("tmp");
838
839 return $temp_name;
840 }
static getDataDir()
get data directory (outside webspace)
static createDirectory(string $a_dir, int $a_mod=0755)
create directory

References createDirectory(), and getDataDir().

Referenced by ilImagemapPreview\__construct(), ilTestExport\aggregatedResultsToExcel(), ilObjUserFolder\buildExportFile(), ilTestArchiveService\buildOverviewFilename(), ilVirusScanner\createBufferFile(), ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob\createDirectory(), ilRestFileStorage\createFile(), ilAdvancedMDParser\createLocalRecord(), ilTestExportGUI\createTestArchiveExport(), ilExerciseManagementCollectFilesJob\createUniqueTempDirectory(), ilCopyWorkspaceFilesToTempDirectoryJob\createUniqueTempDirectory(), ilCopyFilesToTempDirectoryJob\createUniqueTempDirectory(), ilCalendarCopyFilesToTempDirectoryJob\createUniqueTempDirectory(), ilObjTest\deliverPDFfromFO(), ilMediaItem\determineDuration(), ilPageLayoutAdministrationGUI\exportLayout(), ilTestExport\exportToExcel(), ilHtmlToPdfTransformerFactory\generateTempPath(), ilWkhtmlToPdfRenderer\getTempFileName(), ilUserDataSet\getXmlRecord(), ilFileXMLParser\handlerEndTag(), assOrderingQuestionImport\handleUploadedFile(), ilDidacticTemplateSettingsGUI\importTemplate(), ilAssFileUploadUploadsExporter\initFilenames(), ilGhostscriptRenderer\renderImages(), ilExAssignment\sendMultiFeedbackStructureFile(), ilExcel\sendToClient(), ilRestFileStorage\storeFileForRest(), ilECSConnector\updateResource(), ilCalendarCategoryGUI\uploadAppointments(), ilObjSAHSLearningModuleGUI\uploadObject(), ilObjLanguageExtGUI\uploadObject(), ilPersonalProfileGUI\uploadUserPicture(), and ilExcel\writeToTmpFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeDir()

static ilFileUtils::makeDir ( string  $a_dir)
static

creates a new directory and inherits all filesystem permissions of the parent directory You may pass only the name of your new directory or with the entire path or relative path information.

examples: a_dir = /tmp/test/your_dir a_dir = ../test/your_dir a_dir = your_dir (--> creates your_dir in current directory)

@access public

Parameters
string[path] + directory name
Returns
boolean
Deprecated:
in favour of Filesystem::createDir() located at the filesystem service.
See also
\ILIAS\Filesystem\Filesystem::createDir()

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

424 : bool
425 {
426 $a_dir = trim($a_dir);
427
428 // remove trailing slash (bugfix for php 4.2.x)
429 if (substr($a_dir, -1) == "/") {
430 $a_dir = substr($a_dir, 0, -1);
431 }
432
433 // check if a_dir comes with a path
434 if (!($path = substr(
435 $a_dir,
436 0,
437 strrpos($a_dir, "/") - strlen($a_dir)
438 ))) {
439 $path = ".";
440 }
441
442 // create directory with file permissions of parent directory
443 if (is_dir($a_dir)) {
444 return true;
445 }
446 $old_mask = umask(0000);
447 $result = @mkdir($a_dir, fileperms($path));
448 umask($old_mask);
449
450 return $result;
451 }
$path
Definition: ltiservices.php:32

References $path.

Referenced by ilFileDataCourse\__checkImportPath(), ilFileDataCourse\__checkPath(), ilFileDataCourse\__initDirectory(), ilObjStyleSheet\_createImagesDirectory(), ilObjTest\_createImportDirectory(), ilObjQuestionPool\_createImportDirectory(), ilFileDataCourse\addDirectory(), ILIAS\Wiki\Export\WikiHtmlExport\buildExportFile(), ilGlossaryExport\buildExportFileXML(), ilSurveyExport\buildExportFileXML(), ilTestExport\buildExportFileXML(), ilQuestionpoolExport\buildExportFileXML(), ilTestExport\buildExportResultFile(), ilQuestionPageParser\copyMobFiles(), ilContainer\createContainerDirectory(), ilObjFileBasedLM\createDataDirectory(), ilObjSAHSLearningModule\createDataDirectory(), ilChatroomConfigFileHandler\createDataDirIfNotExists(), ilCOPageHTMLExport\createDirectories(), ilFileSystemGUI\createDirectory(), createDirectory(), ilObjSurvey\createExportDirectory(), ilObjSurveyQuestionPool\createExportDirectory(), ilObjTest\createExportDirectory(), ilObjQuestionPool\createExportDirectory(), ilObjStyleSheet\createExportDirectory(), ilObjUserFolder\createExportDirectory(), ilObjStyleSheet\createExportSubDirectory(), ilObjGlossary\createImportDirectory(), ilObjContentObject\createImportDirectory(), ilObjSurvey\createImportDirectory(), ilObjSurveyQuestionPool\createImportDirectory(), ilObjStyleSheet\createImportDirectory(), ilFileDataCourse\createOnlineVersion(), ilMediaItem\determineDuration(), ilObjTest\exportFileItems(), ilObjQuestionPool\exportFileItems(), ilObjFileBasedLMGUI\exportHTML(), ilCOPageHTMLExport\exportHTMLFile(), ilCOPageHTMLExport\exportHTMLMOB(), ilPageLayoutAdministrationGUI\exportLayout(), ilObjLanguageExt\getDataPath(), ilUserDataSet\getXmlRecord(), ILIAS\Blog\Export\BlogHtmlExport\initDirectories(), ILIAS\Glossary\Export\GlossaryHtmlExport\initDirectories(), ILIAS\LearningModule\Export\LMHtmlExport\initDirectories(), ILIAS\Portfolio\Export\PortfolioHtmlExport\initDirectories(), ILIAS\Notes\Export\NotesHtmlExport\initDirectories(), ilFileDataImport\initExportDirectory(), ilSCORM13PlayerGUI\logDirectory(), ilExAssignment\sendMultiFeedbackStructureFile(), ilForumXMLWriter\start(), ilFSStorageExercise\uploadFile(), ilObjSAHSLearningModuleGUI\uploadObject(), ilPersonalProfileGUI\uploadUserPicture(), and ILIAS\LearningModule\Export\LMHtmlExport\zipPackage().

+ Here is the caller graph for this function:

◆ makeDirParents()

static ilFileUtils::makeDirParents ( string  $a_dir)
static

Create a new directory and all parent directories.

Creates a new directory and inherits all filesystem permissions of the parent directory If the parent directories doesn't exist, they will be created recursively. The directory name NEEDS TO BE an absolute path, because it seems that relative paths are not working with PHP's file_exists function.

Parameters
string$a_dirThe directory name to be created @access public
Returns
bool
Author
Helmut Schottmüller hscho.nosp@m.ttm@.nosp@m.tzi.d.nosp@m.e
Deprecated:
in favour of Filesystem::createDir() located at the filesystem service.
See also
\ILIAS\Filesystem\Filesystem::createDir()

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

298 : bool
299 {
300 $dirs = [$a_dir];
301 $a_dir = dirname($a_dir);
302 $last_dirname = '';
303 while ($last_dirname != $a_dir) {
304 array_unshift($dirs, $a_dir);
305 $last_dirname = $a_dir;
306 $a_dir = dirname($a_dir);
307 }
308
309 // find the first existing dir
310 $reverse_paths = array_reverse($dirs, true);
311 $found_index = -1;
312 foreach ($reverse_paths as $key => $value) {
313 if ($found_index == -1) {
314 if (is_dir($value)) {
315 $found_index = $key;
316 }
317 }
318 }
319
320 $old_mask = umask(0000);
321 foreach ($dirs as $dirindex => $dir) {
322 // starting with the longest existing path
323 if ($dirindex >= $found_index) {
324 if (!file_exists($dir)) {
325 if (strcmp(substr($dir, strlen($dir) - 1, 1), "/") == 0) {
326 // on some systems there is an error when there is a slash
327 // at the end of a directory in mkdir, see Mantis #2554
328 $dir = substr($dir, 0, strlen($dir) - 1);
329 }
330 if (!mkdir($dir)) {
331 error_log("Can't make directory: $dir");
332 return false;
333 }
334 } elseif (!is_dir($dir)) {
335 error_log("$dir is not a directory");
336 return false;
337 } else {
338 // get umask of the last existing parent directory
339 $umask = fileperms($dir);
340 }
341 }
342 }
343 umask($old_mask);
344
345 return true;
346 }
string $key
Consumer key/client ID value.
Definition: System.php:193

References ILIAS\LTI\ToolProvider\$key.

Referenced by ilChatroomAdminSmileyGUI\_checkSetup(), ilHtmlPurifierAbstractLibWrapper\_getCacheDirectory(), ilExportContainer\addSubitems(), assMatchingQuestion\afterSyncWithOriginal(), assSingleChoice\afterSyncWithOriginal(), ilTestPlayerAbstractGUI\archiveParticipantSubmission(), assLongMenu\assertDirExists(), ilQuestionpoolExport\buildExportFileXML(), ilTestSubmissionReviewGUI\buildPdfFilename(), ilAssFileUploadUploadsExporter\collectUploadedFiles(), assFlashQuestion\copyApplet(), ilCalendarCopyFilesToTempDirectoryJob\copyFiles(), ilCopyFilesToTempDirectoryJob\copyFiles(), ilCopyWorkspaceFilesToTempDirectoryJob\copyFiles(), ilExerciseManagementCollectFilesJob\copyFileToSubDirectory(), assImagemapQuestion\copyImage(), assMatchingQuestion\copyImages(), assMultipleChoice\copyImages(), assOrderingQuestion\copyImages(), assQuestion\copySuggestedSolutionFiles(), ilFSStorageExercise\create(), ilIndividualAssessmentFileStorage\create(), ilUserCertificateZip\createArchiveDirectory(), ilTestArchiver\createArchiveForTest(), ilLoggingErrorFileStorage\createDir(), ilCOPageHTMLExport\createDirectories(), ilSystemStyleHTMLExport\createDirectories(), ILIAS\MediaCast\BackgroundTasks\DownloadAllCollectFilesJob\createDirectory(), ilFSStorageSession\createDirectory(), ilObjMediaObject\createDirectory(), ilExplorerBaseGUI\createHTMLExportDirs(), ilCopyFilesToTempDirectoryJob\createTargetDirectory(), ilExerciseManagementCollectFilesJob\createTargetDirectory(), ilCopyWorkspaceFilesToTempDirectoryJob\createTargetDirectory(), ilCalendarCopyFilesToTempDirectoryJob\createTargetDirectory(), ilTestExportGUI\createTestArchiveExport(), ilExerciseManagementCollectFilesJob\createUniqueTempDirectory(), ilCopyWorkspaceFilesToTempDirectoryJob\createUniqueTempDirectory(), ilCopyFilesToTempDirectoryJob\createUniqueTempDirectory(), ilCalendarCopyFilesToTempDirectoryJob\createUniqueTempDirectory(), ilFileDataForum\createZipFile(), ilFileDataForumDrafts\createZipFile(), assFlashQuestion\duplicateApplet(), assImagemapQuestion\duplicateImage(), assMatchingQuestion\duplicateImages(), assSingleChoice\duplicateImages(), assOrderingQuestion\duplicateImages(), SurveyQuestion\duplicateMaterials(), assQuestion\duplicateSuggestedSolutionFiles(), assOrderingQuestion\ensureImagePathExists(), assOrderingQuestionImport\ensureImagePathExists(), ilDclContentExporter\export(), ilExportContainer\exportObject(), ilCOPageHTMLExport\exportQuestionFiles(), ILIAS\Services\Export\HTML\Util\exportResourceFile(), ilCOPageHTMLExport\exportStyles(), ILIAS\User\Export\UserHtmlExport\exportUserImages(), assFlashQuestionImport\fromXML(), assImagemapQuestionImport\fromXML(), assKprimChoiceImport\fromXML(), assMultipleChoiceImport\fromXML(), assSingleChoiceImport\fromXML(), ilHtmlToPdfTransformerFactory\generateTempPath(), ilBadgeHandler\getBadgePath(), ilFSStorageExercise\getFeedbackPath(), ilFSStorageExercise\getGlobalFeedbackPath(), ilMediaImageUtil\getImageSize(), ilObjSurvey\getImportDirectory(), ilBadgeHandler\getInstancePath(), ilFSStorageExercise\getMultiFeedbackUploadPath(), ilMediaObjectDataSet\getXmlRecord(), ilBibliographicExporter\getXmlRepresentation(), ilContentPageExporter\getXmlRepresentation(), ilDataCollectionExporter\getXmlRepresentation(), ilFileExporter\getXmlRepresentation(), ilForumExporter\getXmlRepresentation(), ilIndividualAssessmentExporter\getXmlRepresentation(), ilSurveyExporter\getXmlRepresentation(), ilStyleExporter\getXmlRepresentation(), assKprimChoice\handleFileUpload(), ilAdvancedMDRecordExportFiles\init(), ilAdvancedMDRecordImportFiles\init(), ilFileDataForumDrafts\initDirectory(), ilFSStorageCourse\initInfoDirectory(), ilFSStorageCourse\initMemberExportDirectory(), ilFSStorageGroup\initMemberExportDirectory(), assFlashQuestion\moveAppletIfExists(), assFlashQuestion\moveUploadedFile(), ilObjSurveyQuestionPool\pasteFromClipboard(), ilObjQuestionPool\pasteFromClipboard(), ilOrgUnitType\processAndStoreIconFile(), assMatchingQuestionImport\saveImage(), assFileUpload\savePreviewData(), assFileUpload\saveWorkingData(), ilOrgUnitExporter\sendAndCreateSimpleExportFile(), assMultipleChoice\setImageFile(), assSingleChoice\setImageFile(), assMatchingQuestion\setImageFile(), assImagemapQuestion\setImageFilename(), SurveyQuestion\setMaterialsfile(), assQuestionGUI\suggestedsolution(), assMultipleChoice\syncImages(), assSingleChoice\syncImages(), ilCertificateBackgroundImageUpload\uploadBackgroundImage(), ilObjCertificateSettings\uploadBackgroundImage(), and ilObjStyleSheet\writeCSSFile().

+ Here is the caller graph for this function:

◆ moveUploadedFile()

static ilFileUtils::moveUploadedFile ( string  $a_file,
string  $a_name,
string  $a_target,
bool  $a_raise_errors = true,
string  $a_mode = "move_uploaded" 
)
static

move uploaded file

Parameters
string$a_file
string$a_name
string$a_target
bool$a_raise_errors
string$a_mode
Returns
bool
Exceptions
ilExceptionThrown if no uploaded files are found and raise error is set to true.
Deprecated:
in favour of the FileUpload service.
See also
\ILIAS\DI\Containerupload()

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

510 : bool {
511 global $DIC;
512 $main_tpl = $DIC->ui()->mainTemplate();
513 $target_filename = basename($a_target);
514
515 $target_filename = ilFileUtils::getValidFilename($target_filename);
516
517 // Make sure the target is in a valid subfolder. (e.g. no uploads to ilias/setup/....)
518 [$target_filesystem, $target_dir] = self::sanitateTargetPath($a_target);
519
520 $upload = $DIC->upload();
521
522 // If the upload has not yet been processed make sure he gets processed now.
523 if (!$upload->hasBeenProcessed()) {
524 $upload->process();
525 }
526
527 try {
528 if (!$upload->hasUploads()) {
529 throw new ilException(
530 $DIC->language()->txt("upload_error_file_not_found")
531 );
532 }
533 $upload_result = $upload->getResults()[$a_file] ?? null;
534 if ($upload_result instanceof UploadResult) {
535 if (!$upload_result->isOK()) {
536 throw new ilException($upload_result->getStatus()->getMessage());
537 }
538 } else {
539 return false;
540 }
541 } catch (ilException $e) {
542 if (!$a_raise_errors) {
543 $main_tpl->setOnScreenMessage('failure', $e->getMessage(), true);
544 } else {
545 throw $e;
546 }
547
548 return false;
549 }
550
551 $upload->moveOneFileTo(
552 $upload_result,
553 $target_dir,
554 $target_filesystem,
555 $target_filename,
556 true
557 );
558
559 return true;
560 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static sanitateTargetPath(string $a_target)
static getValidFilename(string $a_filename)

Referenced by ilPCInteractiveImageGUI\create(), ilCourseFile\create(), ilSessionFile\create(), assKprimChoice\handleFileUpload(), ilExAssignment\handleGlobalFeedbackFileUpload(), ilObjStyleSheet\import(), ilObjSurveyQuestionPoolGUI\importFileObject(), ilExcCriteriaFile\importFromPeerReviewForm(), ilDidacticTemplateSettingsGUI\importTemplate(), assFlashQuestion\moveUploadedFile(), ilAdvancedMDRecordImportFiles\moveUploadedFile(), assQuestion\moveUploadedMediaFile(), ilObjSCORMLearningModuleGUI\newModuleVersionUpload(), ilOrgUnitType\processAndStoreIconFile(), assFileUpload\savePreviewData(), ilObjMediaObjectGUI\savePropertiesObject(), assFileUpload\saveWorkingData(), assMultipleChoice\setImageFile(), assSingleChoice\setImageFile(), assMatchingQuestion\setImageFile(), assImagemapQuestion\setImageFilename(), SurveyQuestion\setMaterialsfile(), assOrderingQuestion\storeImageFile(), ilFileDataMail\storeUploadedFile(), ilFileDataForum\storeUploadedFile(), ilFileDataForumDrafts\storeUploadedFile(), assQuestionGUI\suggestedsolution(), ilPCInteractiveImageGUI\update(), ilCalendarCategoryGUI\uploadAppointments(), ilFSStorageExercise\uploadAssignmentFiles(), ilFSWebStorageExercise\uploadAssignmentFiles(), ilCertificateBackgroundImageUpload\uploadBackgroundImage(), ilObjCertificateSettings\uploadBackgroundImage(), ilFSStorageExercise\uploadFile(), ilBookingObject\uploadFile(), ilIndividualAssessmentFileStorage\uploadFile(), ilObjBlog\uploadImage(), ilObjPoll\uploadImage(), ilBadge\uploadImage(), ilBadgeImageTemplate\uploadImage(), ilExAssignment\uploadMultiFeedbackFile(), ilObjSAHSLearningModuleGUI\uploadObject(), ilBookingObject\uploadPostFile(), ilObjQuestionPoolGUI\uploadQplObject(), ilObjSurveyQuestionPoolGUI\uploadQuestionsObject(), ilObjTestGUI\uploadTst(), and ilObjUserGUI\uploadUserPictureObject().

+ Here is the caller graph for this function:

◆ processZipFile()

static ilFileUtils::processZipFile ( string  $a_directory,
string  $a_file,
bool  $structure 
)
static
Deprecated:
Will be removed completely with ILIAS 9

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

41 : void {
42 global $DIC;
43
44 $lng = $DIC->language();
45
46 $pathinfo = pathinfo($a_file);
47 $file = $pathinfo["basename"];
48
49 // see 22727
50 if ($pathinfo["extension"] ?? '' === '') {
51 $file .= ".zip";
52 }
53
54 // Copy zip-file to new directory, unzip and remove it
55 // TODO: check archive for broken file
56 //copy ($a_file, $a_directory . "/" . $file);
57 self::moveUploadedFile($a_file, $file, $a_directory . "/" . $file);
58 self::unzip($a_directory . "/" . $file);
59 unlink($a_directory . "/" . $file);
60 //echo "-".$a_directory . "/" . $file."-";
61 // Stores filename and paths into $filearray to check for viruses
62 // Checks if filenames can be read, else -> throw exception and leave
63 $filearray = [];
64 ilFileUtils::recursive_dirscan($a_directory, $filearray);
65
66 // if there are no files unziped (->broken file!)
67 if (empty($filearray)) {
68 throw new ilFileUtilsException(
69 $lng->txt("archive_broken"),
71 );
72 }
73
74 // virus handling
75 foreach ($filearray["file"] as $key => $value) {
76 // remove "invisible" files
77 if (substr($value, 0, 1) == "." || stristr(
78 $filearray["path"][$key],
79 "/__MACOSX/"
80 )) {
81 unlink($filearray["path"][$key] . $value);
82 unset($filearray["path"][$key]);
83 unset($filearray["file"][$key]);
84 continue;
85 }
86
87 $vir = ilVirusScanner::virusHandling($filearray["path"][$key], $value);
88 if (!$vir[0]) {
89 // Unlink file and throw exception
90 unlink($filearray['path'][$key]);
91 throw new ilFileUtilsException(
92 $lng->txt("file_is_infected") . "<br />" . $vir[1],
94 );
95 } elseif ($vir[1] != "") {
96 throw new ilFileUtilsException(
97 $vir[1],
99 );
100 }
101 }
102
103 // If archive is to be used "flat"
104 $doublettes = '';
105 if (!$structure) {
106 foreach (array_count_values($filearray["file"]) as $key => $value) {
107 // Archive contains same filenames in different directories
108 if ($value != "1") {
109 $doublettes .= " '" . ilFileUtils::utf8_encode($key) . "'";
110 }
111 }
112 if (strlen($doublettes) > 0) {
113 throw new ilFileUtilsException(
114 $lng->txt("exc_upload_error") . "<br />" . $lng->txt(
115 "zip_structure_error"
116 ) . $doublettes,
118 );
119 }
120 } else {
121 $mac_dir = $a_directory . "/__MACOSX";
122 if (file_exists($mac_dir)) {
123 self::delDir($mac_dir);
124 }
125 }
126 }
static utf8_encode(string $string)
utf8-encodes string if it is not a valid utf8-string.
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
static recursive_dirscan(string $dir, array &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
static virusHandling(string $a_file, string $a_orig_name='', bool $a_clean=true)

◆ rCopy()

static ilFileUtils::rCopy ( string  $a_sdir,
string  $a_tdir,
bool  $preserveTimeAttributes = false 
)
static

Copies content of a directory $a_sdir recursively to a directory $a_tdir.

Parameters
string$a_sdirsource directory
string$a_tdirtarget directory
boolean$preserveTimeAttributesif true, ctime will be kept.
Returns
boolean TRUE for sucess, FALSE otherwise
Exceptions

ILIAS\Filesystem\Exception\DirectoryNotFoundException

Exceptions

ILIAS\Filesystem\Exception\FileNotFoundException

Exceptions

ILIAS\Filesystem\Exception\IOException @access public

Deprecated:
in favour of Filesystem::copyDir() located at the filesystem service.
See also
Filesystem::copyDir()

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

246 : bool {
247 $sourceFS = LegacyPathHelper::deriveFilesystemFrom($a_sdir);
248 $targetFS = LegacyPathHelper::deriveFilesystemFrom($a_tdir);
249
250 $sourceDir = LegacyPathHelper::createRelativePath($a_sdir);
251 $targetDir = LegacyPathHelper::createRelativePath($a_tdir);
252
253 // check if arguments are directories
254 if (!$sourceFS->hasDir($sourceDir)) {
255 return false;
256 }
257
258 $sourceList = $sourceFS->listContents($sourceDir, true);
259
260 foreach ($sourceList as $item) {
261 if ($item->isDir()) {
262 continue;
263 }
264 try {
265 $itemPath = $targetDir . '/' . substr(
266 $item->getPath(),
267 strlen($sourceDir)
268 );
269 $stream = $sourceFS->readStream($item->getPath());
270 $targetFS->writeStream($itemPath, $stream);
271 } catch (\ILIAS\Filesystem\Exception\FileAlreadyExistsException $e) {
272 // Do nothing with that type of exception
273 }
274 }
275
276 return true;
277 }
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
Class ChatMainBarProvider \MainMenu\Provider.

Referenced by assMatchingQuestion\afterSyncWithOriginal(), assSingleChoice\afterSyncWithOriginal(), ilExAssignment\cloneAssignmentsOfExercise(), ilObjStyleSheet\copyImagesToDir(), ilQuestionPageParser\copyMobFiles(), ilPreview\copyPreviews(), ilObjectCustomIconImpl\createFromImportDir(), ilFileDataCourse\createOnlineVersion(), ilObjCmiXapi\doCloneObject(), ilObjMediaObject\duplicate(), ilObjStyleSheet\export(), ilObjFileBasedLMGUI\exportHTML(), ilCOPageHTMLExport\exportHTMLMOB(), ilCOPageHTMLExport\exportQuestionFiles(), ilCOPageHTMLExport\exportStyles(), ilObjStyleSheet\import(), ilBlogDataSet\importRecord(), ilPortfolioDataSet\importRecord(), ilMediaObjectDataSet\importRecord(), ilStyleDataSet\importRecord(), ilObjSAHSLearningModule\populateByDirectoy(), and ilFileDataCourse\rCopy().

+ Here is the caller graph for this function:

◆ recursive_dirscan()

static ilFileUtils::recursive_dirscan ( string  $dir,
array &  $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
Deprecated:
Will be removed completely with ILIAS 9

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

137 : void
138 {
139 global $DIC;
140
141 $lng = $DIC->language();
142
143 $dirlist = opendir($dir);
144 while (false !== ($file = readdir($dirlist))) {
145 if (!is_file($dir . "/" . $file) && !is_dir($dir . "/" . $file)) {
146 throw new ilFileUtilsException(
147 $lng->txt("filenames_not_supported"),
149 );
150 }
151
152 if ($file != '.' && $file != '..') {
153 $newpath = $dir . '/' . $file;
154 $level = explode('/', $newpath);
155 if (is_dir($newpath)) {
156 ilFileUtils::recursive_dirscan($newpath, $arr);
157 } else {
158 $arr["path"][] = $dir . "/";
159 $arr["file"][] = end($level);
160 }
161 }
162 }
163 closedir($dirlist);
164 }

References ilFileUtilsException\$BROKEN_FILE, $DIC, $lng, and recursive_dirscan().

Referenced by ilObjFileBasedLMGUI\afterSave(), recursive_dirscan(), and ilFileSystemGUI\unzipFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeTrailingPathSeparators()

◆ rename()

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

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

210 : bool
211 {
212 $pi = pathinfo($a_target);
213 global $DIC;
214 $sanitizer = new ilFileServicesFilenameSanitizer(
215 $DIC->fileServiceSettings()
216 );
217
218 if (!$sanitizer->isClean($a_target)) {
219 throw new ilFileUtilsException("Invalid target file");
220 }
221
222 return rename($a_source, $a_target);
223 }
static rename(string $a_source, string $a_target)

References $DIC.

Referenced by ilAssFileUploadUploadsExporter\createFileUploadCollectionZipFile(), assFlashQuestion\moveAppletIfExists(), ilObjSCORMLearningModuleGUI\newModuleVersionUpload(), ilDclMobRecordFieldModel\parseValue(), ilObjSurveyQuestionPool\pasteFromClipboard(), ilFileSystemGUI\renameFile(), ilFileDataForum\rotateFiles(), ilFileDataForumDrafts\rotateFiles(), ilFileDataMail\rotateFiles(), assOrderingQuestion\updateImageFile(), ilFSStorageExercise\uploadFile(), and ilObjSAHSLearningModuleGUI\uploadObject().

+ Here is the caller graph for this function:

◆ renameExecutables()

static ilFileUtils::renameExecutables ( string  $a_dir)
static
Deprecated:

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

943 : void
944 {
945 $def_arr = explode(",", SUFFIX_REPL_DEFAULT);
946 foreach ($def_arr as $def) {
947 self::rRenameSuffix($a_dir, trim($def), "sec");
948 }
949
950 $def_arr = explode(",", SUFFIX_REPL_ADDITIONAL);
951 foreach ($def_arr as $def) {
952 self::rRenameSuffix($a_dir, trim($def), "sec");
953 }
954 }
static rRenameSuffix(string $a_dir, string $a_old_suffix, string $a_new_suffix)
Renames all files with certain suffix and gives them a new suffix.

Referenced by ilPCInteractiveImageGUI\create(), ilObjMediaPoolGUI\createMediaFromUploadDir(), ilObjSCORMLearningModuleGUI\newModuleVersionUpload(), ilDclMobRecordFieldModel\parseValue(), ilObjSAHSLearningModule\populateByDirectoy(), ilFileSystemGUI\renameFile(), ilCmiXapiContentUploadImporter\sanitizeObjectDirectory(), assQuestionGUI\suggestedsolution(), ilFileSystemGUI\unzipFile(), ilFileSystemGUI\uploadFile(), and ilObjSAHSLearningModuleGUI\uploadObject().

+ Here is the caller graph for this function:

◆ rRenameSuffix()

static ilFileUtils::rRenameSuffix ( string  $a_dir,
string  $a_old_suffix,
string  $a_new_suffix 
)
static

Renames all files with certain suffix and gives them a new suffix.

This words recursively through a directory.

Deprecated:

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

962 : bool
963 {
964 if ($a_dir === "/"
965 || $a_dir === ""
966 || strpos($a_dir, "..") !== false
967 || trim($a_old_suffix) === "") {
968 return false;
969 }
970
971 // check if argument is directory
972 if (!@is_dir($a_dir)) {
973 return false;
974 }
975
976 // read a_dir
977 $dir = opendir($a_dir);
978 if ($dir === false) {
979 return false;
980 }
981
982 $prohibited = [
983 '...'
984 ];
985
986 while ($file = readdir($dir)) {
987 if (
988 $file !== "."
989 && $file !== ".."
990 ) {
991 // triple dot is not allowed in filenames
992 if (in_array($file, $prohibited)) {
993 unlink($a_dir . "/" . $file);
994 continue;
995 }
996
997 // directories
998 if (@is_dir($a_dir . "/" . $file)) {
999 self::rRenameSuffix($a_dir . "/" . $file, $a_old_suffix, $a_new_suffix);
1000 }
1001
1002 // files
1003 if (@is_file($a_dir . "/" . $file)) {
1004 // first check for files with trailing dot
1005 if (strrpos($file, '.') == (strlen($file) - 1)) {
1006 try {
1007 rename($a_dir . '/' . $file, substr($a_dir . '/' . $file, 0, -1));
1008 } catch (Throwable $t) {
1009 // to avoid exploits we do delete this file and continue renaming
1010 unlink($a_dir . '/' . $file);
1011 continue;
1012 }
1013
1014 $file = substr($file, 0, -1);
1015 }
1016
1017 $path_info = pathinfo($a_dir . "/" . $file);
1018
1019 if (strtolower($path_info["extension"] ?? '') === strtolower($a_old_suffix)) {
1020 $pos = strrpos($a_dir . "/" . $file, ".");
1021 $new_name = substr($a_dir . "/" . $file, 0, $pos) . "." . $a_new_suffix;
1022 // check if file exists
1023 if (file_exists($new_name)) {
1024 if (is_dir($new_name)) {
1025 self::delDir($new_name);
1026 } else {
1027 unlink($new_name);
1028 }
1029 }
1030 rename($a_dir . "/" . $file, $new_name);
1031 }
1032 }
1033 }
1034 }
1035 return true;
1036 }

Referenced by ilObjMediaObject\renameExecutables().

+ Here is the caller graph for this function:

◆ sanitateTargetPath()

static ilFileUtils::sanitateTargetPath ( string  $a_target)
staticprotected

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

453 : array
454 {
455 switch (true) {
456 case strpos($a_target, ILIAS_WEB_DIR . '/' . CLIENT_ID) === 0:
457 case strpos(
458 $a_target,
459 './' . ILIAS_WEB_DIR . '/' . CLIENT_ID
460 ) === 0:
461 case strpos($a_target, CLIENT_WEB_DIR) === 0:
462 $targetFilesystem = \ILIAS\FileUpload\Location::WEB;
463 break;
464 case strpos($a_target, CLIENT_DATA_DIR . "/temp") === 0:
465 $targetFilesystem = \ILIAS\FileUpload\Location::TEMPORARY;
466 break;
467 case strpos($a_target, CLIENT_DATA_DIR) === 0:
468 $targetFilesystem = \ILIAS\FileUpload\Location::STORAGE;
469 break;
470 case strpos($a_target, ILIAS_ABSOLUTE_PATH . '/Customizing') === 0:
471 $targetFilesystem = \ILIAS\FileUpload\Location::CUSTOMIZING;
472 break;
473 default:
474 throw new InvalidArgumentException(
475 "Can not move files to \"$a_target\" because path can not be mapped to web, storage or customizing location."
476 );
477 }
478
479 $absTargetDir = dirname($a_target);
480 $targetDir = LegacyPathHelper::createRelativePath($absTargetDir);
481
482 return [$targetFilesystem, $targetDir];
483 }
const CLIENT_WEB_DIR
Definition: constants.php:47
const TEMPORARY
The ILIAS temporary directory.
Definition: Location.php:50
const CUSTOMIZING
The filesystem within the web root where all the skins and plugins are saved.
Definition: Location.php:45
const WEB
The filesystem within the ilias web root.
Definition: Location.php:35
const STORAGE
The filesystem outside of the ilias web root.
Definition: Location.php:40

References CLIENT_DATA_DIR, CLIENT_ID, CLIENT_WEB_DIR, ILIAS\FileUpload\Location\CUSTOMIZING, ILIAS_WEB_DIR, ILIAS\FileUpload\Location\STORAGE, ILIAS\FileUpload\Location\TEMPORARY, and ILIAS\FileUpload\Location\WEB.

◆ unzip()

static ilFileUtils::unzip ( string  $path_to_zip_file,
bool  $overwrite_existing = false,
bool  $unpack_flat = false 
)
static

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

846 : void {
847 global $DIC;
848
849 $sanitizer = new ilFileServicesFilenameSanitizer(
850 $DIC->fileServiceSettings()
851 );
852
853 $log = $DIC->logger()->root();
854
855 if (!is_file($path_to_zip_file)) {
856 return;
857 }
858
859 // we unpack the zip always in a temp directory
860 $temporary_unzip_directory = self::ilTempnam();
861 self::makeDir($temporary_unzip_directory);
862 copy($path_to_zip_file, $temporary_unzip_directory . DIRECTORY_SEPARATOR . basename($path_to_zip_file));
863 $original_path_to_zip_file = $path_to_zip_file;
864 $path_to_zip_file = $temporary_unzip_directory . DIRECTORY_SEPARATOR . basename($path_to_zip_file);
865 $original_zip_path_info = pathinfo($original_path_to_zip_file);
866 $unzippable_zip_path_info = pathinfo($path_to_zip_file);
867
868 $unzippable_zip_directory = $unzippable_zip_path_info["dirname"];
869 $unzippable_zip_filename = $unzippable_zip_path_info["basename"];
870
871 // unzip
872 $current_directory = getcwd();
873 chdir($unzippable_zip_directory);
874 $unzip_command = PATH_TO_UNZIP;
875
876 // real unzip
877 if (!$overwrite_existing) {
878 $unzip_parameters = ilShellUtil::escapeShellArg($unzippable_zip_filename);
879 } else {
880 $unzip_parameters = "-o " . ilShellUtil::escapeShellArg($unzippable_zip_filename);
881 }
882 ilShellUtil::execQuoted($unzip_command, $unzip_parameters);
883 // move back
884 chdir($current_directory);
885
886 // remove all sym links
887 clearstatcache(); // prevent is_link from using cache
888 $dir_realpath = realpath($unzippable_zip_directory);
889 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($unzippable_zip_directory)) as $name => $f) {
890 if (is_link($name)) {
891 $target = readlink($name);
892 if (substr($target, 0, strlen($dir_realpath)) != $dir_realpath) {
893 unlink($name);
894 $log->info("Removed symlink " . $name);
895 }
896 }
897 if (is_file($name) && $name !== $sanitizer->sanitize($name)) {
898 // rename file if it contains invalid suffix
900 rename($name, $new_name);
901 }
902 }
903
904 // rename executables
905 self::renameExecutables($unzippable_zip_directory);
906
907 // now we have to move the files to the original directory.
908 // if $a_flat is true, we move the files only without directories, otherwise we move the whole directory.
909 // since some provide a realtive path here, we have to get the absolute path first
910 $target_dir_name = $original_zip_path_info["dirname"];
911 $target_dir_name = realpath($target_dir_name);
912
913 if ($unpack_flat) {
914 $file_array = [];
915 self::recursive_dirscan($temporary_unzip_directory, $file_array);
916 if (is_array($file_array["file"])) {
917 foreach ($file_array["file"] as $k => $f) {
918 if (
919 substr($f, 0, 1) !== "."
920 && $f !== basename($original_path_to_zip_file)
921 ) {
922 copy(
923 $file_array["path"][$k] . $f,
924 $target_dir_name . DIRECTORY_SEPARATOR . $f
925 );
926 }
927 }
928 }
929 } else {
930 $target_directory = $target_dir_name;
932 $temporary_unzip_directory,
933 $target_directory
934 );
935 }
936
937 self::delDir($temporary_unzip_directory);
938 }
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static renameExecutables(string $a_dir)
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static escapeShellArg(string $a_arg)
static execQuoted(string $cmd, ?string $args=null)
if($format !==null) $name
Definition: metadata.php:247
$log
Definition: result.php:33

Referenced by ilExportContainer\addSubitems(), ilSurveyExporter\getXmlRepresentation(), ilObjUserFolderGUI\handleUploadedFiles(), ilObjStyleSheet\import(), ilObjSurveyQuestionPool\importObject(), ilObjSCORMLearningModuleGUI\newModuleVersionUpload(), ilExerciseManagementGUI\openSubmissionViewObject(), ilCmiXapiImporter\prepareLocalSourceStorage(), ilCertificateUtilHelper\unzip(), ilFileSystemGUI\unzipFile(), ilExAssignment\uploadMultiFeedbackFile(), ilObjSAHSLearningModuleGUI\uploadObject(), ilObjQuestionPoolGUI\uploadQplObject(), and ilObjTestGUI\uploadTst().

+ Here is the caller graph for this function:

◆ utf8_encode()

static ilFileUtils::utf8_encode ( string  $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 175 of file class.ilFileUtils.php.

175 : string
176 {
177
178 // From http://w3.org/International/questions/qa-forms-utf-8.html
179 return (preg_match(
180 '%^(?:
181 [\x09\x0A\x0D\x20-\x7E] # ASCII
182 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
183 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
184 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
185 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
186 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
187 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
188 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
189 )*$%xs',
190 $string
191 )) ? $string : utf8_encode($string);
192 }

◆ zip()

static ilFileUtils::zip ( string  $a_dir,
string  $a_file,
bool  $compress_content = false 
)
static

zips given directory/file into given zip.file

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

572 : bool {
573 $cdir = getcwd();
574
575 if ($compress_content) {
576 $a_dir .= "/*";
577 $pathinfo = pathinfo($a_dir);
578 chdir($pathinfo["dirname"]);
579 }
580
581 $pathinfo = pathinfo($a_file);
582 $dir = $pathinfo["dirname"];
583 $file = $pathinfo["basename"];
584
585 if (!$compress_content) {
586 chdir($dir);
587 }
588
589 $zip = PATH_TO_ZIP;
590
591 if (!$zip) {
592 chdir($cdir);
593 return false;
594 }
595
596 if (is_array($a_dir)) {
597 $source = "";
598 foreach ($a_dir as $dir) {
599 $name = basename($dir);
601 }
602 } else {
603 $name = basename($a_dir);
604 if (trim($name) != "*") {
606 } else {
607 $source = $name;
608 }
609 }
610
611 $zipcmd = "-r " . ilShellUtil::escapeShellArg($a_file) . " " . $source;
612 ilShellUtil::execQuoted($zip, $zipcmd);
613 chdir($cdir);
614 return true;
615 }
$source
Definition: metadata.php:93

Referenced by ILIAS\Wiki\Export\WikiHtmlExport\buildExportFile(), ilQuestionpoolExport\buildExportFileXLS(), ilGlossaryExport\buildExportFileXML(), ilSurveyExport\buildExportFileXML(), ilTestExport\buildExportFileXML(), ilQuestionpoolExport\buildExportFileXML(), ilTestArchiver\compressTestArchive(), ilAssFileUploadUploadsExporter\createFileUploadCollectionZipFile(), ilSkinStyleContainer\createTempZip(), ilFileDataForum\createZipFile(), ilFileDataForumDrafts\createZipFile(), ilObjStyleSheet\export(), ilObjFileBasedLMGUI\exportHTML(), ilExportContainer\exportObject(), ILIAS\MediaCast\BackgroundTasks\DownloadAllZipJob\run(), ilZipJob\run(), ilCalendarZipJob\run(), ilOrgUnitExporter\sendAndCreateSimpleExportFile(), ilExAssignment\sendMultiFeedbackStructureFile(), ilCertificateUtilHelper\zip(), ilUserCertificateZip\zipCertificatesInArchiveDirectory(), ilFileDataCourse\zipFile(), ILIAS\Blog\Export\BlogHtmlExport\zipPackage(), ILIAS\Glossary\Export\GlossaryHtmlExport\zipPackage(), ILIAS\LearningModule\Export\LMHtmlExport\zipPackage(), ILIAS\Portfolio\Export\PortfolioHtmlExport\zipPackage(), and ILIAS\Notes\Export\NotesHtmlExport\zipPackage().

+ Here is the caller graph for this function:

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