Ec (2); PHP File Upload classic code functionFileUpload ($ resourceType, $ currentFolder, $ sCommand) {& nbsp; if (! Isset ($ _ FILES) {& nbsp; global $ _ FILES; & nbsp ;}& nbsp; $ sErrorNumber0; & nbsp; $ sFileName script ec (2); script
PHP File Upload classic code
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 ['secureimageupload'])
{
If ($ isImageValid = IsImageValid ($ oFile ['tmp _ name'], $ sExtension) === false)
{
$ SErrorNumber = '123 ';
}
}
If (isset ($ Config ['htmlextension'])
{
If (! IsHtmlExtension ($ sExtension, $ Config ['htmlextension']) &
($ DetectHtml = DetectHtml ($ oFile ['tmp _ name']) = true)
{
$ SErrorNumber = '123 ';
}
}
// 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 = '123 ';
}
Else
{
Move_uploaded_file ($ oFile ['tmp _ name'], $ sFilePath );
If (is_file ($ sFilePath ))
{
If (isset ($ Config ['chmodonupload']) &! $ Config ['chdonupload'])
{
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 = '123 ';
}
Else if (isset ($ detectHtml) & $ detectHtml ===- 1 & DetectHtml ($ sFilePath) === true)
{
@ Unlink ($ sFilePath );
$ SErrorNumber = '123 ';
}
}
}
Else
$ SErrorNumber = '123 ';
}
Else
$ SErrorNumber = '123 ';
$ SFileUrl = CombinePaths (GetResourceTypePath ($ resourceType, $ sCommand), $ currentFolder );
$ SFileUrl = CombinePaths ($ sFileUrl, $ sFileName );
SendUploadResults ($ sErrorNumber, $ sFileUrl, $ sFileName );
Exit;