28 if (strpos($path,
':') === FALSE) {
29 return str_replace(
'//',
'/', strtr($path,
'\\',
'/'));
31 return preg_replace(
'/^([a-z]{2,}):\//',
'$1://', str_replace(
'//',
'/', strtr($path,
'\\',
'/')));
42 return rtrim($path,
'/') .
'/';
56 return rtrim(self::getUnixStylePath(implode(
'/', $paths)),
'/');
71 static public function readDirectoryRecursively($path, $suffix = NULL, $returnRealPath = FALSE, $returnDotFiles = FALSE, &$filenames = array()) {
72 if (!is_dir($path))
throw new \TYPO3\Flow\Utility\Exception(
'"' . $path .
'" is no directory.', 1207253462);
74 $directoryIterator = new \DirectoryIterator($path);
75 $suffixLength = strlen($suffix);
77 foreach ($directoryIterator as $fileInfo) {
78 $filename = $fileInfo->getFilename();
79 if ($filename ===
'.' || $filename ===
'..' || ($returnDotFiles === FALSE && $filename[0] ===
'.')) {
82 if ($fileInfo->isFile() && ($suffix === NULL || substr($filename, -$suffixLength) === $suffix)) {
83 $filenames[] = self::getUnixStylePath(($returnRealPath === TRUE ? realpath($fileInfo->getPathname()) : $fileInfo->getPathname()));
85 if ($fileInfo->isDir()) {
86 self::readDirectoryRecursively($fileInfo->getPathname(), $suffix, $returnRealPath, $returnDotFiles, $filenames);
102 if (!is_dir($path)) {
103 throw new \TYPO3\Flow\Utility\Exception(
'"' . $path .
'" is no directory.', 1169047616);
106 if (self::is_link($path)) {
107 if (self::unlink($path) !== TRUE) {
108 throw new \TYPO3\Flow\Utility\Exception(
'Could not unlink symbolic link "' . $path .
'".', 1323697654);
111 $directoryIterator = new \RecursiveDirectoryIterator($path);
112 foreach ($directoryIterator as $fileInfo) {
113 if (!$fileInfo->isDir()) {
114 if (self::unlink($fileInfo->getPathname()) !== TRUE) {
115 throw new \TYPO3\Flow\Utility\Exception(
'Could not unlink file "' . $fileInfo->getPathname() .
'".', 1169047619);
117 } elseif (!$directoryIterator->isDot()) {
118 self::removeDirectoryRecursively($fileInfo->getPathname());
135 if (self::is_link($path)) {
136 if (self::unlink($path) !== TRUE) {
137 throw new \TYPO3\Flow\Utility\Exception(
'Could not unlink symbolic link "' . $path .
'".', 1316000297);
140 self::emptyDirectoryRecursively($path);
142 if (rmdir($path) !== TRUE) {
143 throw new \TYPO3\Flow\Utility\Exception(
'Could not remove directory "' . $path .
'".', 1316000298);
146 throw new \TYPO3\Flow\Utility\Exception(
'Could not remove directory "' . $path .
'".', 1323961907);
161 if (substr($path, -2) ===
'/.') {
162 $path = substr($path, 0, -1);
164 if (is_file($path)) {
165 throw new \TYPO3\Flow\Utility\Exception(
'Could not create directory "' . $path .
'", because a file with that name exists!', 1349340620);
167 if (!is_dir($path) && strlen($path) > 0) {
168 $oldMask = umask(000);
169 mkdir($path, 0777, TRUE);
171 if (!is_dir($path)) {
172 throw new \TYPO3\Flow\Utility\Exception(
'Could not create directory "' . $path .
'"!', 1170251400);
194 static public function copyDirectoryRecursively($sourceDirectory, $targetDirectory, $keepExistingFiles = FALSE, $copyDotFiles = FALSE) {
195 if (!is_dir($sourceDirectory)) {
196 throw new \TYPO3\Flow\Utility\Exception(
'"' . $sourceDirectory .
'" is no directory.', 1235428779);
199 self::createDirectoryRecursively($targetDirectory);
200 if (!is_dir($targetDirectory)) {
201 throw new \TYPO3\Flow\Utility\Exception(
'"' . $targetDirectory .
'" is no directory.', 1235428780);
204 $sourceFilenames = self::readDirectoryRecursively($sourceDirectory, NULL, FALSE, $copyDotFiles);
205 foreach ($sourceFilenames as $filename) {
206 $relativeFilename = str_replace($sourceDirectory,
'', $filename);
207 self::createDirectoryRecursively($targetDirectory . dirname($relativeFilename));
208 $targetPathAndFilename = self::concatenatePaths(array($targetDirectory, $relativeFilename));
209 if ($keepExistingFiles === FALSE || !file_exists($targetPathAndFilename)) {
210 copy($filename, $targetPathAndFilename);
226 static public function getFileContents($pathAndFilename, $flags = 0, $context = NULL, $offset = -1, $maximumLength = -1) {
227 if ($flags === TRUE) $flags = FILE_USE_INCLUDE_PATH;
229 if ($maximumLength > -1) {
230 $content = file_get_contents($pathAndFilename, $flags, $context, $offset, $maximumLength);
232 $content = file_get_contents($pathAndFilename, $flags, $context, $offset);
248 switch ($errorCode) {
249 case \UPLOAD_ERR_INI_SIZE:
250 return 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
251 case \UPLOAD_ERR_FORM_SIZE:
252 return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
253 case \UPLOAD_ERR_PARTIAL:
254 return 'The uploaded file was only partially uploaded';
255 case \UPLOAD_ERR_NO_FILE:
256 return 'No file was uploaded';
257 case \UPLOAD_ERR_NO_TMP_DIR:
258 return 'Missing a temporary folder';
259 case \UPLOAD_ERR_CANT_WRITE:
260 return 'Failed to write file to disk';
261 case \UPLOAD_ERR_EXTENSION:
262 return 'File upload stopped by extension';
264 return 'Unknown upload error';
277 static public function is_link($pathAndFilename) {
279 if (DIRECTORY_SEPARATOR ===
'/') {
280 return \is_link($pathAndFilename);
282 if (!file_exists($pathAndFilename)) {
285 $normalizedPathAndFilename = strtolower(rtrim(self::getUnixStylePath($pathAndFilename),
'/'));
286 $normalizedTargetPathAndFilename = strtolower(self::getUnixStylePath(realpath($pathAndFilename)));
287 if ($normalizedTargetPathAndFilename ===
'') {
290 return $normalizedPathAndFilename !== $normalizedTargetPathAndFilename;
299 static public function unlink($pathAndFilename) {
302 if (DIRECTORY_SEPARATOR ===
'/' || is_file($pathAndFilename)) {
303 return @
\unlink($pathAndFilename);
305 return rmdir($pathAndFilename);
static getUploadErrorMessage($errorCode)
static getNormalizedPath($path)
static is_link($pathAndFilename)
static readDirectoryRecursively($path, $suffix=NULL, $returnRealPath=FALSE, $returnDotFiles=FALSE, &$filenames=array())
static copyDirectoryRecursively($sourceDirectory, $targetDirectory, $keepExistingFiles=FALSE, $copyDotFiles=FALSE)
static concatenatePaths(array $paths)
static unlink($pathAndFilename)
static emptyDirectoryRecursively($path)
static createDirectoryRecursively($path)
static getFileContents($pathAndFilename, $flags=0, $context=NULL, $offset=-1, $maximumLength=-1)
static getUnixStylePath($path)
static removeDirectoryRecursively($path)