3 * FCKeditor - The text editor for internet
4 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
6 * Licensed under the terms of the GNU Lesser General Public License:
7 * http://www.opensource.org/licenses/lgpl-license.php
9 * For further information visit:
10 * http://www.fckeditor.net/
12 * "Support Open Source software. What about a donation today?"
15 * This is the File Manager Connector for ASP.
18 * Frederico Caldeira Knabben (fredck@fckeditor.net)
21 function GetUrlFromPath( $resourceType, $folderPath )
23 if ( $resourceType == '' )
24 return RemoveFromEnd( $GLOBALS["UserFilesPath"], '/' ) . $folderPath ;
26 return $GLOBALS["UserFilesPath"] . $resourceType . $folderPath ;
29 function RemoveExtension( $fileName )
31 return substr( $fileName, 0, strrpos( $fileName, '.' ) ) ;
34 function ServerMapFolder( $resourceType, $folderPath )
36 // Get the resource type directory.
37 $sResourceTypePath = $GLOBALS["UserFilesDirectory"] . $resourceType . '/' ;
39 // Ensure that the directory exists.
40 CreateServerFolder( $sResourceTypePath ) ;
42 // Return the resource type directory combined with the required path.
43 return $sResourceTypePath . RemoveFromStart( $folderPath, '/' ) ;
46 function GetParentFolder( $folderPath )
48 $sPattern = "-[/\\\\][^/\\\\]+[/\\\\]?$-" ;
49 return preg_replace( $sPattern, '', $folderPath ) ;
52 function CreateServerFolder( $folderPath )
54 $sParent = GetParentFolder( $folderPath ) ;
56 // Check if the parent exists, or create it.
57 if ( !file_exists( $sParent ) )
59 $sErrorMsg = CreateServerFolder( $sParent ) ;
60 if ( $sErrorMsg != '' )
64 if ( !file_exists( $folderPath ) )
66 // Turn off all error reporting.
67 error_reporting( 0 ) ;
68 // Enable error tracking to catch the error.
69 ini_set( 'track_errors', '1' ) ;
71 // To create the folder with 0777 permissions, we need to set umask to zero.
72 $oldumask = umask(0) ;
73 mkdir( $folderPath, 0777 ) ;
76 $sErrorMsg = $php_errormsg ;
78 // Restore the configurations.
79 ini_restore( 'track_errors' ) ;
80 ini_restore( 'error_reporting' ) ;
88 function GetRootPath()
90 $sRealPath = realpath( './' ) ;
92 $sSelfPath = $_SERVER['PHP_SELF'] ;
93 $sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;
95 return substr( $sRealPath, 0, strlen( $sRealPath ) - strlen( $sSelfPath ) ) ;