1 |
816
|
doc
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
4 |
918
|
Ruebenwurz
|
* Copyright (C) 2003-2009 Frederico Caldeira Knabben
|
5 |
816
|
doc
|
*
|
6 |
|
|
* == BEGIN LICENSE ==
|
7 |
|
|
*
|
8 |
|
|
* Licensed under the terms of any of the following licenses at your
|
9 |
|
|
* choice:
|
10 |
|
|
*
|
11 |
|
|
* - GNU General Public License Version 2 or later (the "GPL")
|
12 |
|
|
* http://www.gnu.org/licenses/gpl.html
|
13 |
|
|
*
|
14 |
|
|
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
|
15 |
|
|
* http://www.gnu.org/licenses/lgpl.html
|
16 |
|
|
*
|
17 |
|
|
* - Mozilla Public License Version 1.1 or later (the "MPL")
|
18 |
|
|
* http://www.mozilla.org/MPL/MPL-1.1.html
|
19 |
|
|
*
|
20 |
|
|
* == END LICENSE ==
|
21 |
|
|
*
|
22 |
|
|
* This is the File Manager Connector for PHP.
|
23 |
|
|
*/
|
24 |
|
|
|
25 |
|
|
function GetFolders( $resourceType, $currentFolder )
|
26 |
|
|
{
|
27 |
|
|
// Map the virtual path to the local server path.
|
28 |
|
|
$sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'GetFolders' ) ;
|
29 |
|
|
|
30 |
|
|
// Array that will hold the folders names.
|
31 |
|
|
$aFolders = array() ;
|
32 |
|
|
|
33 |
1038
|
Ruebenwurz
|
$oCurrentFolder = @opendir( $sServerDir ) ;
|
34 |
816
|
doc
|
|
35 |
1038
|
Ruebenwurz
|
if ($oCurrentFolder !== false)
|
36 |
816
|
doc
|
{
|
37 |
1038
|
Ruebenwurz
|
while ( $sFile = readdir( $oCurrentFolder ) )
|
38 |
|
|
{
|
39 |
|
|
if ( $sFile != '.' && $sFile != '..' && is_dir( $sServerDir . $sFile ) )
|
40 |
|
|
$aFolders[] = '<Folder name="' . ConvertToXmlAttribute( $sFile ) . '" />' ;
|
41 |
|
|
}
|
42 |
|
|
closedir( $oCurrentFolder ) ;
|
43 |
816
|
doc
|
}
|
44 |
|
|
|
45 |
|
|
// Open the "Folders" node.
|
46 |
|
|
echo "<Folders>" ;
|
47 |
|
|
|
48 |
|
|
natcasesort( $aFolders ) ;
|
49 |
|
|
foreach ( $aFolders as $sFolder )
|
50 |
|
|
echo $sFolder ;
|
51 |
|
|
|
52 |
|
|
// Close the "Folders" node.
|
53 |
|
|
echo "</Folders>" ;
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
function GetFoldersAndFiles( $resourceType, $currentFolder )
|
57 |
|
|
{
|
58 |
|
|
// Map the virtual path to the local server path.
|
59 |
|
|
$sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'GetFoldersAndFiles' ) ;
|
60 |
|
|
|
61 |
|
|
// Arrays that will hold the folders and files names.
|
62 |
|
|
$aFolders = array() ;
|
63 |
|
|
$aFiles = array() ;
|
64 |
|
|
|
65 |
1038
|
Ruebenwurz
|
$oCurrentFolder = @opendir( $sServerDir ) ;
|
66 |
816
|
doc
|
|
67 |
1038
|
Ruebenwurz
|
if ($oCurrentFolder !== false)
|
68 |
816
|
doc
|
{
|
69 |
1038
|
Ruebenwurz
|
while ( $sFile = readdir( $oCurrentFolder ) )
|
70 |
816
|
doc
|
{
|
71 |
1038
|
Ruebenwurz
|
if ( $sFile != '.' && $sFile != '..' )
|
72 |
816
|
doc
|
{
|
73 |
1038
|
Ruebenwurz
|
if ( is_dir( $sServerDir . $sFile ) )
|
74 |
|
|
$aFolders[] = '<Folder name="' . ConvertToXmlAttribute( $sFile ) . '" />' ;
|
75 |
|
|
else
|
76 |
816
|
doc
|
{
|
77 |
1038
|
Ruebenwurz
|
$iFileSize = @filesize( $sServerDir . $sFile ) ;
|
78 |
|
|
if ( !$iFileSize ) {
|
79 |
|
|
$iFileSize = 0 ;
|
80 |
|
|
}
|
81 |
|
|
if ( $iFileSize > 0 )
|
82 |
|
|
{
|
83 |
|
|
$iFileSize = round( $iFileSize / 1024 ) ;
|
84 |
|
|
if ( $iFileSize < 1 )
|
85 |
|
|
$iFileSize = 1 ;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
$aFiles[] = '<File name="' . ConvertToXmlAttribute( $sFile ) . '" size="' . $iFileSize . '" />' ;
|
89 |
816
|
doc
|
}
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
1038
|
Ruebenwurz
|
closedir( $oCurrentFolder ) ;
|
93 |
816
|
doc
|
}
|
94 |
|
|
|
95 |
|
|
// Send the folders
|
96 |
|
|
natcasesort( $aFolders ) ;
|
97 |
|
|
echo '<Folders>' ;
|
98 |
|
|
|
99 |
|
|
foreach ( $aFolders as $sFolder )
|
100 |
|
|
echo $sFolder ;
|
101 |
|
|
|
102 |
|
|
echo '</Folders>' ;
|
103 |
|
|
|
104 |
|
|
// Send the files
|
105 |
|
|
natcasesort( $aFiles ) ;
|
106 |
|
|
echo '<Files>' ;
|
107 |
|
|
|
108 |
|
|
foreach ( $aFiles as $sFiles )
|
109 |
|
|
echo $sFiles ;
|
110 |
|
|
|
111 |
|
|
echo '</Files>' ;
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
function CreateFolder( $resourceType, $currentFolder )
|
115 |
|
|
{
|
116 |
|
|
if (!isset($_GET)) {
|
117 |
|
|
global $_GET;
|
118 |
|
|
}
|
119 |
|
|
$sErrorNumber = '0' ;
|
120 |
|
|
$sErrorMsg = '' ;
|
121 |
|
|
|
122 |
|
|
if ( isset( $_GET['NewFolderName'] ) )
|
123 |
|
|
{
|
124 |
|
|
$sNewFolderName = $_GET['NewFolderName'] ;
|
125 |
|
|
$sNewFolderName = SanitizeFolderName( $sNewFolderName ) ;
|
126 |
|
|
|
127 |
|
|
if ( strpos( $sNewFolderName, '..' ) !== FALSE )
|
128 |
|
|
$sErrorNumber = '102' ; // Invalid folder name.
|
129 |
|
|
else
|
130 |
|
|
{
|
131 |
|
|
// Map the virtual path to the local server path of the current folder.
|
132 |
|
|
$sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'CreateFolder' ) ;
|
133 |
|
|
|
134 |
|
|
if ( is_writable( $sServerDir ) )
|
135 |
|
|
{
|
136 |
|
|
$sServerDir .= $sNewFolderName ;
|
137 |
|
|
|
138 |
|
|
$sErrorMsg = CreateServerFolder( $sServerDir ) ;
|
139 |
|
|
|
140 |
|
|
switch ( $sErrorMsg )
|
141 |
|
|
{
|
142 |
|
|
case '' :
|
143 |
|
|
$sErrorNumber = '0' ;
|
144 |
|
|
break ;
|
145 |
|
|
case 'Invalid argument' :
|
146 |
|
|
case 'No such file or directory' :
|
147 |
|
|
$sErrorNumber = '102' ; // Path too long.
|
148 |
|
|
break ;
|
149 |
|
|
default :
|
150 |
|
|
$sErrorNumber = '110' ;
|
151 |
|
|
break ;
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
else
|
155 |
|
|
$sErrorNumber = '103' ;
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
else
|
159 |
|
|
$sErrorNumber = '102' ;
|
160 |
|
|
|
161 |
|
|
// Create the "Error" node.
|
162 |
1038
|
Ruebenwurz
|
echo '<Error number="' . $sErrorNumber . '" />' ;
|
163 |
816
|
doc
|
}
|
164 |
|
|
|
165 |
|
|
function FileUpload( $resourceType, $currentFolder, $sCommand )
|
166 |
|
|
{
|
167 |
|
|
if (!isset($_FILES)) {
|
168 |
|
|
global $_FILES;
|
169 |
|
|
}
|
170 |
|
|
$sErrorNumber = '0' ;
|
171 |
|
|
$sFileName = '' ;
|
172 |
|
|
|
173 |
|
|
if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) )
|
174 |
|
|
{
|
175 |
|
|
global $Config ;
|
176 |
|
|
|
177 |
|
|
$oFile = $_FILES['NewFile'] ;
|
178 |
|
|
|
179 |
|
|
// Map the virtual path to the local server path.
|
180 |
|
|
$sServerDir = ServerMapFolder( $resourceType, $currentFolder, $sCommand ) ;
|
181 |
|
|
|
182 |
|
|
// Get the uploaded file name.
|
183 |
|
|
$sFileName = $oFile['name'] ;
|
184 |
|
|
$sFileName = SanitizeFileName( $sFileName ) ;
|
185 |
|
|
|
186 |
|
|
$sOriginalFileName = $sFileName ;
|
187 |
|
|
|
188 |
|
|
// Get the extension.
|
189 |
|
|
$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
|
190 |
|
|
$sExtension = strtolower( $sExtension ) ;
|
191 |
|
|
|
192 |
|
|
if ( isset( $Config['SecureImageUploads'] ) )
|
193 |
|
|
{
|
194 |
|
|
if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false )
|
195 |
|
|
{
|
196 |
|
|
$sErrorNumber = '202' ;
|
197 |
|
|
}
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
if ( isset( $Config['HtmlExtensions'] ) )
|
201 |
|
|
{
|
202 |
|
|
if ( !IsHtmlExtension( $sExtension, $Config['HtmlExtensions'] ) &&
|
203 |
|
|
( $detectHtml = DetectHtml( $oFile['tmp_name'] ) ) === true )
|
204 |
|
|
{
|
205 |
|
|
$sErrorNumber = '202' ;
|
206 |
|
|
}
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
// Check if it is an allowed extension.
|
210 |
|
|
if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) )
|
211 |
|
|
{
|
212 |
|
|
$iCounter = 0 ;
|
213 |
|
|
|
214 |
|
|
while ( true )
|
215 |
|
|
{
|
216 |
|
|
$sFilePath = $sServerDir . $sFileName ;
|
217 |
|
|
|
218 |
|
|
if ( is_file( $sFilePath ) )
|
219 |
|
|
{
|
220 |
|
|
$iCounter++ ;
|
221 |
|
|
$sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
|
222 |
|
|
$sErrorNumber = '201' ;
|
223 |
|
|
}
|
224 |
|
|
else
|
225 |
|
|
{
|
226 |
|
|
move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
|
227 |
|
|
|
228 |
|
|
if ( is_file( $sFilePath ) )
|
229 |
|
|
{
|
230 |
|
|
if ( isset( $Config['ChmodOnUpload'] ) && !$Config['ChmodOnUpload'] )
|
231 |
|
|
{
|
232 |
|
|
break ;
|
233 |
|
|
}
|
234 |
|
|
|
235 |
1199
|
Luisehahne
|
$permissions = defined('OCTAL_DIR_MODE') ? OCTAL_DIR_MODE : 0777;
|
236 |
816
|
doc
|
|
237 |
1199
|
Luisehahne
|
|
238 |
816
|
doc
|
if ( isset( $Config['ChmodOnUpload'] ) && $Config['ChmodOnUpload'] )
|
239 |
|
|
{
|
240 |
|
|
$permissions = $Config['ChmodOnUpload'] ;
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
$oldumask = umask(0) ;
|
244 |
|
|
chmod( $sFilePath, $permissions ) ;
|
245 |
|
|
umask( $oldumask ) ;
|
246 |
|
|
}
|
247 |
|
|
|
248 |
|
|
break ;
|
249 |
|
|
}
|
250 |
|
|
}
|
251 |
|
|
|
252 |
|
|
if ( file_exists( $sFilePath ) )
|
253 |
|
|
{
|
254 |
|
|
//previous checks failed, try once again
|
255 |
|
|
if ( isset( $isImageValid ) && $isImageValid === -1 && IsImageValid( $sFilePath, $sExtension ) === false )
|
256 |
|
|
{
|
257 |
|
|
@unlink( $sFilePath ) ;
|
258 |
|
|
$sErrorNumber = '202' ;
|
259 |
|
|
}
|
260 |
|
|
else if ( isset( $detectHtml ) && $detectHtml === -1 && DetectHtml( $sFilePath ) === true )
|
261 |
|
|
{
|
262 |
|
|
@unlink( $sFilePath ) ;
|
263 |
|
|
$sErrorNumber = '202' ;
|
264 |
|
|
}
|
265 |
|
|
}
|
266 |
|
|
}
|
267 |
|
|
else
|
268 |
|
|
$sErrorNumber = '202' ;
|
269 |
|
|
}
|
270 |
|
|
else
|
271 |
|
|
$sErrorNumber = '202' ;
|
272 |
|
|
|
273 |
|
|
|
274 |
|
|
$sFileUrl = CombinePaths( GetResourceTypePath( $resourceType, $sCommand ) , $currentFolder ) ;
|
275 |
|
|
$sFileUrl = CombinePaths( $sFileUrl, $sFileName ) ;
|
276 |
|
|
|
277 |
|
|
SendUploadResults( $sErrorNumber, $sFileUrl, $sFileName ) ;
|
278 |
|
|
|
279 |
|
|
exit ;
|
280 |
|
|
}
|
281 |
1199
|
Luisehahne
|
?>
|