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 [' 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 a 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)
{
& nbsp. @unlink ($sFilePath);
$sErrorNumber = ' 202 ';
}
else if (isset ($detectHtml) && $detectHtml = = 1 && detecthtml ($sFilePat h) = = True)
{
@unlink ($sFilePath);
& nbsp; $sErrorNumber = ' 202 ';
}
}
}
else
$sErrorNumber = ' else ';
$ sErrorNumber = ' The ' of the ';
$SFILEURL = Combinepaths (Getresourcetypepath ($resourceType, $sCommand), $currentFolder);
$SFILEURL = Combinepaths ($SFILEURL, $sFileName);
Senduploadresults ($sErrorNumber, $SFILEURL, $sFileName);
Exit;