Source for file commands.php
Documentation is available at commands.php
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
* For further information visit:
* http://www.fckeditor.net/
* "Support Open Source software. What about a donation today?"
* File Name: commands.php
* This is the File Manager Connector for PHP.
* Frederico Caldeira Knabben (fredck@fckeditor.net)
function GetFolders( $resourceType, $currentFolder )
// Map the virtual path to the local server path.
// Array that will hold the folders names.
$oCurrentFolder = opendir( $sServerDir ) ;
while ( $sFile = readdir( $oCurrentFolder ) )
if ( $sFile != '.' && $sFile != '..' && is_dir( $sServerDir . $sFile ) )
// Open the "Folders" node.
foreach ( $aFolders as $sFolder )
// Close the "Folders" node.
// Map the virtual path to the local server path.
// Arrays that will hold the folders and files names.
$oCurrentFolder = opendir( $sServerDir ) ;
while ( $sFile = readdir( $oCurrentFolder ) )
if ( $sFile != '.' && $sFile != '..' )
if ( is_dir( $sServerDir . $sFile ) )
$iFileSize = filesize( $sServerDir . $sFile ) ;
$iFileSize = round( $iFileSize / 1024 ) ;
if ( $iFileSize < 1 ) $iFileSize = 1 ;
foreach ( $aFolders as $sFolder )
foreach ( $aFiles as $sFiles )
if ( isset ( $_GET['NewFolderName'] ) )
$sNewFolderName = $_GET['NewFolderName'] ;
if ( strpos( $sNewFolderName, '..' ) !== FALSE )
$sErrorNumber = '102' ; // Invalid folder name.
// Map the virtual path to the local server path of the current folder.
$sServerDir .= $sNewFolderName ;
case 'Invalid argument' :
case 'No such file or directory' :
$sErrorNumber = '102' ; // Path too long.
// Create the "Error" node.
echo '<Error number="' . $sErrorNumber . '" originalDescription="' . ConvertToXmlAttribute( $sErrorMsg ) . '" />' ;
function FileUpload( $resourceType, $currentFolder )
if ( isset ( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) )
$oFile = $_FILES['NewFile'] ;
// Map the virtual path to the local server path.
// Get the uploaded file name.
$sFileName = $oFile['name'] ;
$sOriginalFileName = $sFileName ;
$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
$arAllowed = $Config['AllowedExtensions'][$resourceType] ;
$arDenied = $Config['DeniedExtensions'][$resourceType] ;
$perm = octdec(!empty($perm)? $perm: '0660');
if ( ( count($arAllowed) == 0 || in_array( $sExtension, $arAllowed ) ) && ( count($arDenied) == 0 || !in_array( $sExtension, $arDenied ) ) )
$sFilePath = $sServerDir . $sFileName ;
$sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
chmod( $sFilePath, $perm ) ;
echo '<script type="text/javascript">' ;
echo 'window.parent.frames["frmUpload"].OnUploadCompleted(' . $sErrorNumber . ',"' . str_replace( '"', '\\"', $sFileName ) . '") ;' ;
|