28 $sServerDir =
ServerMapFolder( $resourceType, $currentFolder,
'GetFolders' ) ;
33 $oCurrentFolder = @opendir( $sServerDir ) ;
35 if ($oCurrentFolder !==
false)
37 while ( $sFile = readdir( $oCurrentFolder ) )
39 if ( $sFile !=
'.' && $sFile !=
'..' && is_dir( $sServerDir . $sFile ) )
42 closedir( $oCurrentFolder ) ;
48 natcasesort( $aFolders ) ;
49 foreach ( $aFolders as $sFolder )
59 $sServerDir =
ServerMapFolder( $resourceType, $currentFolder,
'GetFoldersAndFiles' ) ;
65 $oCurrentFolder = @opendir( $sServerDir ) ;
67 if ($oCurrentFolder !==
false)
69 while ( $sFile = readdir( $oCurrentFolder ) )
71 if ( $sFile !=
'.' && $sFile !=
'..' )
73 if ( is_dir( $sServerDir . $sFile ) )
77 $iFileSize = @filesize( $sServerDir . $sFile ) ;
83 $iFileSize = round( $iFileSize / 1024 ) ;
92 closedir( $oCurrentFolder ) ;
96 natcasesort( $aFolders ) ;
99 foreach ( $aFolders as $sFolder )
105 natcasesort( $aFiles ) ;
108 foreach ( $aFiles as $sFiles )
119 $sErrorNumber =
'0' ;
122 if ( isset( $_GET[
'NewFolderName'] ) )
124 $sNewFolderName = $_GET[
'NewFolderName'] ;
127 if ( strpos( $sNewFolderName,
'..' ) !== FALSE )
128 $sErrorNumber =
'102' ;
132 $sServerDir =
ServerMapFolder( $resourceType, $currentFolder,
'CreateFolder' ) ;
134 if ( is_writable( $sServerDir ) )
136 $sServerDir .= $sNewFolderName ;
140 switch ( $sErrorMsg )
143 $sErrorNumber =
'0' ;
145 case 'Invalid argument' :
146 case 'No such file or directory' :
147 $sErrorNumber =
'102' ;
150 $sErrorNumber =
'110' ;
155 $sErrorNumber =
'103' ;
159 $sErrorNumber =
'102' ;
162 echo
'<Error number="' . $sErrorNumber .
'" />' ;
167 if (!isset($_FILES)) {
170 $sErrorNumber =
'0' ;
173 if ( isset( $_FILES[
'NewFile'] ) && !is_null( $_FILES[
'NewFile'][
'tmp_name'] ) )
177 $oFile = $_FILES[
'NewFile'] ;
183 $sFileName = $oFile[
'name'] ;
186 $sOriginalFileName = $sFileName ;
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'] ) )
203 ( $detectHtml =
DetectHtml( $oFile[
'tmp_name'] ) ) ===
true )
205 $sErrorNumber =
'202' ;
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 ) )
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' ;
ConvertToXmlAttribute($value)
GetFolders($resourceType, $currentFolder)
SanitizeFolderName($sNewFolderName)
GetFoldersAndFiles($resourceType, $currentFolder)
GetResourceTypePath($resourceType, $sCommand)
IsAllowedExt($sExtension, $resourceType)
DetectHtml($filePath)
Detect HTML in the first KB to prevent against potential security issue with IE/Safari/Opera file typ...
SendUploadResults($errorNumber, $fileUrl= '', $fileName= '', $customMsg= '')
RemoveExtension($fileName)
CreateServerFolder($folderPath, $lastFolder=null)
CreateFolder($resourceType, $currentFolder)
IsHtmlExtension($ext, $htmlExtensions)
Check whether given extension is in html etensions list.
IsImageValid($filePath, $extension)
Check file content.
CombinePaths($sBasePath, $sFolder)
SanitizeFileName($sNewFileName)
FileUpload($resourceType, $currentFolder, $sCommand)
ServerMapFolder($resourceType, $folderPath, $sCommand)