3
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
4
* Copyright (C) 2003-2010 Frederico Caldeira Knabben
8
* Licensed under the terms of any of the following licenses at your
11
* - GNU General Public License Version 2 or later (the "GPL")
12
* http://www.gnu.org/licenses/gpl.html
14
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
15
* http://www.gnu.org/licenses/lgpl.html
17
* - Mozilla Public License Version 1.1 or later (the "MPL")
18
* http://www.mozilla.org/MPL/MPL-1.1.html
22
* This is the File Manager Connector for PHP.
25
function GetFolders( $resourceType, $currentFolder )
27
// Map the virtual path to the local server path.
28
$sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'GetFolders' ) ;
30
// Array that will hold the folders names.
33
$oCurrentFolder = @opendir( $sServerDir ) ;
35
if ($oCurrentFolder !== false)
37
while ( $sFile = readdir( $oCurrentFolder ) )
39
if ( $sFile != '.' && $sFile != '..' && is_dir( $sServerDir . $sFile ) )
40
$aFolders[] = '<Folder name="' . ConvertToXmlAttribute( $sFile ) . '" />' ;
42
closedir( $oCurrentFolder ) ;
45
// Open the "Folders" node.
48
natcasesort( $aFolders ) ;
49
foreach ( $aFolders as $sFolder )
52
// Close the "Folders" node.
56
function GetFoldersAndFiles( $resourceType, $currentFolder )
58
// Map the virtual path to the local server path.
59
$sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'GetFoldersAndFiles' ) ;
61
// Arrays that will hold the folders and files names.
65
$oCurrentFolder = @opendir( $sServerDir ) ;
67
if ($oCurrentFolder !== false)
69
while ( $sFile = readdir( $oCurrentFolder ) )
71
if ( $sFile != '.' && $sFile != '..' )
73
if ( is_dir( $sServerDir . $sFile ) )
74
$aFolders[] = '<Folder name="' . ConvertToXmlAttribute( $sFile ) . '" />' ;
77
$iFileSize = @filesize( $sServerDir . $sFile ) ;
83
$iFileSize = round( $iFileSize / 1024 ) ;
88
$aFiles[] = '<File name="' . ConvertToXmlAttribute( $sFile ) . '" size="' . $iFileSize . '" />' ;
92
closedir( $oCurrentFolder ) ;
96
natcasesort( $aFolders ) ;
99
foreach ( $aFolders as $sFolder )
105
natcasesort( $aFiles ) ;
108
foreach ( $aFiles as $sFiles )
114
function CreateFolder( $resourceType, $currentFolder )
119
$sErrorNumber = '0' ;
122
if ( isset( $_GET['NewFolderName'] ) )
124
$sNewFolderName = $_GET['NewFolderName'] ;
125
$sNewFolderName = SanitizeFolderName( $sNewFolderName ) ;
127
if ( strpos( $sNewFolderName, '..' ) !== FALSE )
128
$sErrorNumber = '102' ; // Invalid folder name.
131
// Map the virtual path to the local server path of the current folder.
132
$sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'CreateFolder' ) ;
134
if ( is_writable( $sServerDir ) )
136
$sServerDir .= $sNewFolderName ;
138
$sErrorMsg = CreateServerFolder( $sServerDir ) ;
140
switch ( $sErrorMsg )
143
$sErrorNumber = '0' ;
145
case 'Invalid argument' :
146
case 'No such file or directory' :
147
$sErrorNumber = '102' ; // Path too long.
150
$sErrorNumber = '110' ;
155
$sErrorNumber = '103' ;
159
$sErrorNumber = '102' ;
161
// Create the "Error" node.
162
echo '<Error number="' . $sErrorNumber . '" />' ;
165
function FileUpload( $resourceType, $currentFolder, $sCommand )
167
if (!isset($_FILES)) {
170
$sErrorNumber = '0' ;
173
if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) )
177
$oFile = $_FILES['NewFile'] ;
179
// Map the virtual path to the local server path.
180
$sServerDir = ServerMapFolder( $resourceType, $currentFolder, $sCommand ) ;
182
// Get the uploaded file name.
183
$sFileName = $oFile['name'] ;
184
$sFileName = SanitizeFileName( $sFileName ) ;
186
$sOriginalFileName = $sFileName ;
188
// Get the extension.
189
$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
190
$sExtension = strtolower( $sExtension ) ;
192
if ( isset( $Config['SecureImageUploads'] ) )
194
if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false )
196
$sErrorNumber = '202' ;
200
if ( isset( $Config['HtmlExtensions'] ) )
202
if ( !IsHtmlExtension( $sExtension, $Config['HtmlExtensions'] ) &&
203
( $detectHtml = DetectHtml( $oFile['tmp_name'] ) ) === true )
205
$sErrorNumber = '202' ;
209
// Check if it is an allowed extension.
210
if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) )
216
$sFilePath = $sServerDir . $sFileName ;
218
if ( is_file( $sFilePath ) )
221
$sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
222
$sErrorNumber = '201' ;
226
move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
228
if ( is_file( $sFilePath ) )
230
if ( isset( $Config['ChmodOnUpload'] ) && !$Config['ChmodOnUpload'] )
237
if ( isset( $Config['ChmodOnUpload'] ) && $Config['ChmodOnUpload'] )
239
$permissions = $Config['ChmodOnUpload'] ;
242
$oldumask = umask(0) ;
243
chmod( $sFilePath, $permissions ) ;
251
if ( file_exists( $sFilePath ) )
253
//previous checks failed, try once again
254
if ( isset( $isImageValid ) && $isImageValid === -1 && IsImageValid( $sFilePath, $sExtension ) === false )
256
@unlink( $sFilePath ) ;
257
$sErrorNumber = '202' ;
259
else if ( isset( $detectHtml ) && $detectHtml === -1 && DetectHtml( $sFilePath ) === true )
261
@unlink( $sFilePath ) ;
262
$sErrorNumber = '202' ;
267
$sErrorNumber = '202' ;
270
$sErrorNumber = '202' ;
273
$sFileUrl = CombinePaths( GetResourceTypePath( $resourceType, $sCommand ) , $currentFolder ) ;
274
$sFileUrl = CombinePaths( $sFileUrl, $sFileName ) ;
276
SendUploadResults( $sErrorNumber, $sFileUrl, $sFileName ) ;