' ; } closedir( $oCurrentFolder ) ; // Open the "Folders" node. echo "" ; natcasesort( $aFolders ) ; foreach ( $aFolders as $sFolder ) echo $sFolder ; // Close the "Folders" node. echo "" ; } function GetFoldersAndFiles( $resourceType, $currentFolder ) { // Map the virtual path to the local server path. $sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'GetFoldersAndFiles' ) ; // Arrays that will hold the folders and files names. $aFolders = array() ; $aFiles = array() ; $oCurrentFolder = opendir( $sServerDir ) ; while ( $sFile = readdir( $oCurrentFolder ) ) { if ( $sFile != '.' && $sFile != '..' ) { if ( is_dir( $sServerDir . $sFile ) ) $aFolders[] = '' ; else { $iFileSize = @filesize( $sServerDir . $sFile ) ; if ( !$iFileSize ) { $iFileSize = 0 ; } if ( $iFileSize > 0 ) { $iFileSize = round( $iFileSize / 1024 ) ; if ( $iFileSize < 1 ) $iFileSize = 1 ; } $aFiles[] = '' ; } } } // Send the folders natcasesort( $aFolders ) ; echo '' ; foreach ( $aFolders as $sFolder ) echo $sFolder ; echo '' ; // Send the files natcasesort( $aFiles ) ; echo '' ; foreach ( $aFiles as $sFiles ) echo $sFiles ; echo '' ; } function CreateFolder( $resourceType, $currentFolder ) { if (!isset($_GET)) { global $_GET; } $sErrorNumber = '0' ; $sErrorMsg = '' ; if ( isset( $_GET['NewFolderName'] ) ) { $sNewFolderName = $_GET['NewFolderName'] ; $sNewFolderName = SanitizeFolderName( $sNewFolderName ) ; if ( strpos( $sNewFolderName, '..' ) !== FALSE ) $sErrorNumber = '102' ; // Invalid folder name. else { // Map the virtual path to the local server path of the current folder. $sServerDir = ServerMapFolder( $resourceType, $currentFolder, 'CreateFolder' ) ; if ( is_writable( $sServerDir ) ) { $sServerDir .= $sNewFolderName ; $sErrorMsg = CreateServerFolder( $sServerDir ) ; switch ( $sErrorMsg ) { case '' : $sErrorNumber = '0' ; break ; case 'Invalid argument' : case 'No such file or directory' : $sErrorNumber = '102' ; // Path too long. break ; default : $sErrorNumber = '110' ; break ; } } else $sErrorNumber = '103' ; } } else $sErrorNumber = '102' ; // Create the "Error" node. echo '' ; } function DeleteFolder($resourceType, $currentFolder, $folderPath) { $sServerDir = ServerMapFolder( $resourceType, $folderPath, '' ) ; deleteDir($sServerDir); exit; } function deleteDir($dirName) { if (empty($dirName)) { return true; } if (file_exists($dirName)) { $dir = dir($dirName); while ($file = $dir->read()) { if ($file != '.' && $file != '..') { if (is_dir($dirName . '/' . $file)) { deleteDir($dirName . '/' . $file); } else { $sFilePath = $dirName . '/' . $file; $sThumbPath = str_replace('userfiles/fck/', 'userfiles/fckthumbs/', $sFilePath); Qs_ImageFs::delIcons($sThumbPath); @unlink($sFilePath); } } } $dir->close(); $dirThumb = str_replace('userfiles/fck/', 'userfiles/fckthumbs/', $dirName); if (file_exists($dirThumb)) { @rmdir($dirThumb); } @rmdir($dirName); } return true; } function FileUpload( $resourceType, $currentFolder, $sCommand ) { if (!isset($_FILES)) { global $_FILES; } $sErrorNumber = '0' ; $sFileName = '' ; if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) ) { global $Config ; $oFile = $_FILES['NewFile'] ; // Map the virtual path to the local server path. $sServerDir = ServerMapFolder( $resourceType, $currentFolder, $sCommand ) ; // Get the uploaded file name. $sFileName = $oFile['name'] ; $sFileName = SanitizeFileName( $sFileName ) ; $sOriginalFileName = $sFileName ; // Get the extension. $sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ; $sExtension = strtolower( $sExtension ) ; if ( isset( $Config['SecureImageUploads'] ) ) { if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false ) { $sErrorNumber = '202' ; } } if ( isset( $Config['HtmlExtensions'] ) ) { if ( !IsHtmlExtension( $sExtension, $Config['HtmlExtensions'] ) && ( $detectHtml = DetectHtml( $oFile['tmp_name'] ) ) === true ) { $sErrorNumber = '202' ; } } // Check if it is an allowed extension. if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) ) { $iCounter = 0 ; while ( true ) { $sFilePath = $sServerDir . $sFileName ; if ( is_file( $sFilePath ) ) { $iCounter++ ; $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ; $sErrorNumber = '201' ; } else { move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ; if ( is_file( $sFilePath ) ) { if ( isset( $Config['ChmodOnUpload'] ) && !$Config['ChmodOnUpload'] ) { break ; } $permissions = 0777; if ( isset( $Config['ChmodOnUpload'] ) && $Config['ChmodOnUpload'] ) { $permissions = $Config['ChmodOnUpload'] ; } $oldumask = umask(0) ; chmod( $sFilePath, $permissions ) ; umask( $oldumask ) ; } break ; } } if ( file_exists( $sFilePath ) ) { //previous checks failed, try once again if ( isset( $isImageValid ) && $isImageValid === -1 && IsImageValid( $sFilePath, $sExtension ) === false ) { @unlink( $sFilePath ) ; $sErrorNumber = '202' ; } else if ( isset( $detectHtml ) && $detectHtml === -1 && DetectHtml( $sFilePath ) === true ) { @unlink( $sFilePath ) ; $sErrorNumber = '202' ; } } } else $sErrorNumber = '202' ; } else $sErrorNumber = '202' ; $sFileUrl = CombinePaths( GetResourceTypePath( $resourceType, $sCommand ) , $currentFolder ) ; $sFileUrl = CombinePaths( $sFileUrl, $sFileName ) ; SendUploadResults( $sErrorNumber, $sFileUrl, $sFileName ) ; exit ; } function DeleteFile( $resourceType, $currentFolder, $fileName ) { $sServerDir = ServerMapFolder( $resourceType, $currentFolder, '' ) ; $sFilePath = CombinePaths( $sServerDir, $fileName ) ; if ( file_exists( $sFilePath ) ) { $sThumbPath = str_replace('userfiles/fck/', 'userfiles/fckthumbs/', $sFilePath); Qs_ImageFs::delIcons($sThumbPath); @unlink( $sFilePath ) ; } exit ; } ?>