1 | <?php |
---|
2 | /* |
---|
3 | * FCKeditor - The text editor for internet |
---|
4 | * Copyright (C) 2003-2006 Frederico Caldeira Knabben |
---|
5 | * |
---|
6 | * Licensed under the terms of the GNU Lesser General Public License: |
---|
7 | * http://www.opensource.org/licenses/lgpl-license.php |
---|
8 | * |
---|
9 | * For further information visit: |
---|
10 | * http://www.fckeditor.net/ |
---|
11 | * |
---|
12 | * "Support Open Source software. What about a donation today?" |
---|
13 | * |
---|
14 | * File Name: io.php |
---|
15 | * This is the File Manager Connector for ASP. |
---|
16 | * |
---|
17 | * File Authors: |
---|
18 | * Frederico Caldeira Knabben (fredck@fckeditor.net) |
---|
19 | */ |
---|
20 | |
---|
21 | function GetUrlFromPath( $resourceType, $folderPath ) |
---|
22 | { |
---|
23 | if ( $resourceType == '' ) |
---|
24 | return RemoveFromEnd( $GLOBALS["UserFilesPath"], '/' ) . $folderPath ; |
---|
25 | else |
---|
26 | return $GLOBALS["UserFilesPath"] . $resourceType . $folderPath ; |
---|
27 | } |
---|
28 | |
---|
29 | function RemoveExtension( $fileName ) |
---|
30 | { |
---|
31 | return substr( $fileName, 0, strrpos( $fileName, '.' ) ) ; |
---|
32 | } |
---|
33 | |
---|
34 | function ServerMapFolder( $resourceType, $folderPath ) |
---|
35 | { |
---|
36 | // Get the resource type directory. |
---|
37 | $sResourceTypePath = $GLOBALS["UserFilesDirectory"] . $resourceType . '/' ; |
---|
38 | |
---|
39 | // Ensure that the directory exists. |
---|
40 | CreateServerFolder( $sResourceTypePath ) ; |
---|
41 | |
---|
42 | // Return the resource type directory combined with the required path. |
---|
43 | return $sResourceTypePath . RemoveFromStart( $folderPath, '/' ) ; |
---|
44 | } |
---|
45 | |
---|
46 | function GetParentFolder( $folderPath ) |
---|
47 | { |
---|
48 | $sPattern = "-[/\\\\][^/\\\\]+[/\\\\]?$-" ; |
---|
49 | return preg_replace( $sPattern, '', $folderPath ) ; |
---|
50 | } |
---|
51 | |
---|
52 | function CreateServerFolder( $folderPath ) |
---|
53 | { |
---|
54 | $sParent = GetParentFolder( $folderPath ) ; |
---|
55 | |
---|
56 | // Check if the parent exists, or create it. |
---|
57 | if ( !file_exists( $sParent ) ) |
---|
58 | { |
---|
59 | $sErrorMsg = CreateServerFolder( $sParent ) ; |
---|
60 | if ( $sErrorMsg != '' ) |
---|
61 | return $sErrorMsg ; |
---|
62 | } |
---|
63 | |
---|
64 | if ( !file_exists( $folderPath ) ) |
---|
65 | { |
---|
66 | // Turn off all error reporting. |
---|
67 | error_reporting( 0 ) ; |
---|
68 | // Enable error tracking to catch the error. |
---|
69 | ini_set( 'track_errors', '1' ) ; |
---|
70 | |
---|
71 | // To create the folder with 0777 permissions, we need to set umask to zero. |
---|
72 | $oldumask = umask(0) ; |
---|
73 | mkdir( $folderPath, 0777 ) ; |
---|
74 | umask( $oldumask ) ; |
---|
75 | |
---|
76 | $sErrorMsg = $php_errormsg ; |
---|
77 | |
---|
78 | // Restore the configurations. |
---|
79 | ini_restore( 'track_errors' ) ; |
---|
80 | ini_restore( 'error_reporting' ) ; |
---|
81 | |
---|
82 | return $sErrorMsg ; |
---|
83 | } |
---|
84 | else |
---|
85 | return '' ; |
---|
86 | } |
---|
87 | |
---|
88 | function GetRootPath() |
---|
89 | { |
---|
90 | $sRealPath = realpath( './' ) ; |
---|
91 | |
---|
92 | $sSelfPath = $_SERVER['PHP_SELF'] ; |
---|
93 | $sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ; |
---|
94 | |
---|
95 | return substr( $sRealPath, 0, strlen( $sRealPath ) - strlen( $sSelfPath ) ) ; |
---|
96 | } |
---|
97 | ?> |
---|