• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1504
  • Last Modified:

ADDT ASP Upload Error " Type mismatch: 'tNG_isFileInsideBaseFolder' "

I am trying to create a simple insert record and upload image function on an ASP page built using Adobe Dreamweaver Developer Toolkit. I have done this many times before with no problem, however, i have a site now that it refuses to work on, any help from Adobes forum is hopeless so i'm now trying here...

I have created a very basic page with nothing but a form, file field and a submit button.
The ADDT insert record and upload image behaviour have been applied. I have even removed the form validation in an attempt to eliminate error hurdles.

Whenever i try to upload an image, i just get the error:
Type mismatch: 'tNG_isFileInsideBaseFolder', this can be found on line 155 on page tNG_FileUpload.class.asp

The steps i have taken to fix this are the following...
1. Changed upload image folder permission writes.
2. Changed "includes\common\lib\file_upload\Temp\" folder permission writes.
3. Tried different types of files to upload.
4. Made sure the form is "multipart/form-data"
5. Made sure server was compatible - its Windows 2003.
6. Made sure Image Magick was installed on the server.
7. Changed line 155 in tNG_FileUpload.class.asp to:
 If Not tNG_isFileInsideBaseFolder(folder, saveFileName) AND saveFileName<>"" Then
8. Updated all include files on the server.
9. Removed create thumbnail option.
10. Checked i have the correct server libraries configured.

The bizare thing is, i've used the Interakt 3.7 Kollection extension before on the same host before (Different site) and it works fine. The ADDT include files are different though from the 3.7 version.
I've even tried using this others sites include files, but as expected the file versions were not compatible with just a whole new set of errors.

I have built an entire site with ADDT over many months that is virtually finished with this one critical problem.

Many Thanks,
Rob

ADDT v1.0
Dreamweaver CS3
ASP VB
Windows 2003 Server
0
ticallian
Asked:
ticallian
  • 5
  • 3
  • 3
3 Solutions
 
v2MediaCommented:
The type mismatch error is a generalized one that is thrown when you try to use a different data type to the type that is expected. Going by the var name "tNG_isFileInsideBaseFolder", I would expect this to be a boolean. If you were to then assign a string to that var, you'd get a type mismatch.

0
 
RouchieCommented:
Yes I agree with v2Media here.  If tNG_FileUpload.class.asp came with the package you are using to build the site, then it's quite likely this is a bug on their behalf rather than yours.

Given the simplicity of the form you aren't really creating the possibility of errors.  Can you paste the offending line of code for further inspection?
0
 
ticallianAuthor Commented:
The offending area of code is here, with the "tNG_isFileInsideBaseFolder" line highlighted...
          dynamicFolder = KT_DynamicData(folder, tNG, null, false, null, null)
          dynamicFolder = KT_makeIncludedPath(dynamicFolder)
		
          autoRename = false	
          Select case LCase(rename)
            case "auto"
              autoRename = true
            case "none"
            case "custom"
              Set arrArgs = Server.CreateObject("Scripting.Dictionary")
              Set path_info = KT_pathinfo(saveFileName)
              arrArgs("KT_name") = path_info("filename")
              arrArgs("KT_ext") = path_info("extension")
              saveFileName = KT_DynamicData(renameRule, tNG, null, false, arrArgs, null)
            case else
              Response.write "INTERNAL ERROR: Unknown upload rename method."
              Response.End()
            End Select
 
!!!!!---->      If Not tNG_isFileInsideBaseFolder(folder, saveFileName) Then <----!!!!!
 
              Set ret = new tNG_error
              baseFileName = KT_dirname(KT_normalizeAbsoluteFilePath(KT_server_MapPath(dynamicFolder & saveFileName)))
              ret.Init "FOLDER_DEL_SECURITY_ERROR", array(), array(baseFileName, tNG_getBaseFolder(folder))
              Set errObj = ret
              Set Execute = ret
              Exit Function
            End If

Open in new window

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
v2MediaCommented:
Actually, this is only part of the offending code. You also need to post the code that instantiates the vars folder and saveFileName, and the function tNG_isFileInsideBaseFolder as well.
0
 
ticallianAuthor Commented:
This is pretty much the complete file content...

Thanks
Class tNG_FileUpload
	Public tNG	' object
	Public fieldName
	Public formFieldName
	Public dbFieldName
	Public folder
	Public maxSize
	Public allowedExtensions
	Public rename
	Public renameRule
	Public uploadedFileName
	Public dynamicFolder
	Public errObj
 
	Private Sub Class_Initialize()
		Set this = Me
	End Sub
	
	Private Sub Class_Terminate()
	End Sub
 
	Public Sub Init (ByRef tNG__param)
		Set tNG = tNG__param
		formFieldName = ""
		dbFieldName = ""
		folder = ""
		maxSize = 0
		allowedExtensions = array()
		rename = "none"
		renameRule = ""
		uploadedFileName = ""
	 	dynamicFolder  = ""
		Set errObj = nothing
	End Sub
 
	'===========================================
	' Inheritance
	'===========================================
	Public this
	
	Public Sub SetContextObject(ByRef objContext)
		Set this = objContext
	End Sub
	'===========================================
	' End Inheritance
	'===========================================
	
	Public Sub setFormFieldName (formFieldName__param)
		formFieldName = formFieldName__param
	End Sub	
 
	Public Sub setDbFieldName (dbFieldName__param)
		dbFieldName = dbFieldName__param
	End Sub	
 
	Public Sub setFolder (folder__param)
		folder = folder__param
	End Sub	
 
	Public Sub setMaxSize (maxSize__param)
		maxSize = maxSize__param
	End Sub	
	
	Public Sub setAllowedExtensions (allowedExtensions__param)
		arrExtensions = split(allowedExtensions__param, ",")
		Dim i
		For i=0 to ubound(arrExtensions)
			arrExtensions(i) = trim(arrExtensions(i))
		Next
		allowedExtensions  = arrExtensions
	End Sub
 
	Public Sub setRename (rename__param)
		rename = rename__param
	End Sub	
 
	Public Sub setRenameRule (renameRule__param)
		renameRule = renameRule__param
	End Sub	
 
	
	Public Sub Rollback()
		Dim fso: Set fso = Server.CreateObject("Scripting.FileSystemObject")
		On Error Resume Next
		fso.DeleteFile dynamicFolder & uploadedFileName, True
		On Error GoTo 0
		Set fso = Nothing
	End Sub
 
	
	Public Sub deleteThumbnails(folder, oldName)
	End Sub
 
	Public Function Execute()
          If tNG.getTransactionType() = "_import" Then
            Set tNG.uploadObj = this
          End If
 
          Dim ret: Set ret = nothing
          If dbFieldName <> "" Then
            oldFileName = tNG.getSavedValue(dbFieldName)
            saveFileName  = tNG.getColumnValue(dbFieldName)
            If tNG.getColumnType(dbFieldName) <> "FILE_TYPE" Then
              Set ret = new tNG_error
              ret.Init "FILE_UPLOAD_WRONG_COLTYPE", array(), array(dbFieldName)
              ret.addFieldError dbFieldName, "FILE_UPLOAD_WRONG_COLTYPE_D", array(dbFieldName)
              Set errObj = ret
              Set Execute = ret
              Exit Function
            End If
          Else
            oldFileName = KT_DynamicData(renameRule, tNG, null, true, null, null)
            If KT_isSet(tNG.multipleIdx) Then
              saveFileName = Request.Form(formFieldName & "_" & tNG.multipleIdx)    
            Else
              saveFileName = Request.Form(formFieldName)
            End If
          End If
          
          dynamicFolder = KT_DynamicData(folder, tNG, null, false, null, null)
          dynamicFolder = KT_makeIncludedPath(dynamicFolder)
		
          autoRename = false	
          Select case LCase(rename)
            case "auto"
              autoRename = true
            case "none"
            case "custom"
              Set arrArgs = Server.CreateObject("Scripting.Dictionary")
              Set path_info = KT_pathinfo(saveFileName)
              arrArgs("KT_name") = path_info("filename")
              arrArgs("KT_ext") = path_info("extension")
              saveFileName = KT_DynamicData(renameRule, tNG, null, false, arrArgs, null)
            case else
              Response.write "INTERNAL ERROR: Unknown upload rename method."
              Response.End()
            End Select
 
            If Not tNG_isFileInsideBaseFolder(folder, saveFileName) Then 
 
              Set ret = new tNG_error
              baseFileName = KT_dirname(KT_normalizeAbsoluteFilePath(KT_server_MapPath(dynamicFolder & saveFileName)))
              ret.Init "FOLDER_DEL_SECURITY_ERROR", array(), array(baseFileName, tNG_getBaseFolder(folder))
              Set errObj = ret
              Set Execute = ret
              Exit Function
            End If
 
		' Upload File
		Set fileUpload = new KT_fileUpload
		If KT_isSet(tNG.multipleIdx) Then
			fileUpload.setFileInfo formFieldName & "_" & tNG.multipleIdx
		Else
			fileUpload.setFileInfo formFieldName
		End If
		fileUpload.setFolder KT_Server_MapPath(dynamicFolder)
		fileUpload.setRequired false
		fileUpload.setAllowedExtensions allowedExtensions
		fileUpload.setAutoRename autoRename
		fileUpload.setMaxSize maxSize
		uploadedFileName = fileUpload.uploadFile(saveFileName, oldFileName)
 
		updateDB = uploadedFileName
		If fileUpload.hasError() Then
			arrError = fileUpload.getError()
			Set errObj  = new tNG_error
			errObj.Init "FILE_UPLOAD_ERROR", array(arrError(0)), array(arrError(1))
			If dbFieldName <> "" Then
				errObj.addFieldError dbFieldName, "%s", array(arrError(0))
			End If
			Set ret = errObj
		Else
			dynamicFolder = KT_Server_MapPath(dynamicFolder) & "\"
			If uploadedFileName = "" Then	
				Set arrArgs = Server.CreateObject("Scripting.Dictionary")
				If rename = "custom" Then
					Set path_info = KT_pathinfo(oldFileName)
					arrArgs("KT_name") = path_info("filename")
				End If
				tmpFileName = KT_DynamicData(renameRule, tNG, null, false, arrArgs, null)
				If tmpFileName <> "" and oldFileName <> "" and tmpFileName <> oldFileName Then
					Set fso = Server.CreateObject("Scripting.FileSystemObject")
					If fso.FileExists(dynamicFolder & oldFileName) Then
						On Error Resume Next
						fso.MoveFile dynamicFolder & oldFileName, dynamicFolder & tmpFileName 
						uploadedFileName = tmpFileName
						updateDB = uploadedFileName
						If err.Number <> 0 Then
							Set ret = new tNG_error
							ret.Init "FILE_UPLOAD_RENAME", array(), array(dynamicFolder & oldFileName, dynamicFolder & tmpFileName )
						End If
						On Error GoTo 0
 
					End If
				End If	
			End If
 
			If Not KT_isSet(ret) Then
				If tNG.getTransactionType = "_insert"  Or tNG.getTransactionType = "_multipleInsert" Then
					tNG.registerTrigger Array("ERROR", "Trigger_Default_RollBack", 1, Me)
				End If
				this.deleteThumbnails dynamicFolder & "thumbnails\", oldFileName 
				If uploadedFileName <> "" Then
					this.deleteThumbnails dynamicFolder & "thumbnails\", uploadedFileName 
				End If
				If dbFieldName <> "" And uploadedFileName <> "" Then
					Set ret = tNG.afterUpdateField(dbFieldName, updateDB)
				End If
			End If
			If Not KT_isSet(ret) and dbFieldName <> "" Then
				tNG.setRawColumnValue dbFieldName, updateDB
			End If
		End If
		Set errObj = ret
		Set Execute = ret
	End Function
	
End Class	
	
%>

Open in new window

0
 
v2MediaCommented:
Hmm, looks like inadequate error reporting. This process needs to be debugged from the point where uploadFile() is used.  Is any part of the process getting completed: file uploaded, saveFileName inserted/updated in the database?

This isn't all the code used in the whole process, there must be another class included that has the method uploadFile(). Perhaps Class.Files.asp ? Or Class.Folders.asp?

Also, please post how the tNG_FileUpload object is instantiated in your webpage. Usually it's instantiated with some asp and some javascript.

My instinct tells me at this point that the temp directory that uploaded files are stored in is not the place you're expecting it to be and it doesn't have the correct permissions. This returns the temp file name as an error boolean instead of a string for the temp file name.

Rouchie, is there a way to confirm the directory that asp is using for temp file uploads?

0
 
RouchieCommented:
Yes v2Media is correct here, there is some code missing.  Somewhere there should be a function called tNG_isFileInsideBaseFolder which looks something like this...

Public Function tNG_isFileInsideBaseFolder(folder, saveFilename)

>> Rouchie, is there a way to confirm the directory that asp is using for temp file uploads?

This would be down to the programmer when the object was instantiated.  ASP does not have a temporary directory for this kind of thing, and it is declared explicitly.  

ticallian, please post the code I mentioned above, and also your page code so we can see how you are attempting to use the object.
0
 
ticallianAuthor Commented:
Sorry late reply, i've been out of the country. Thanks for the help from both of you.

To continue, i've had a search for the use of the function "tNG_isFileInsideBaseFolder" throughout the entire site but it is only called on the page code shown above and on a page used to delete images called during a record delete function.

As for where "uploadFile()" gets called it can be found in the attached line of code, this same code can be found in the zip file link below in the directory "includes/common/lib/file_upload/KT_FileUploadFunctions.inc.asp". Additionally the files KT_Fileupload.asp and KT_Fileupload.class.asp also in this folder may be of use.

Regarding whether the insert function works, it works fine until the upload file function is called, if i remove this code, everything inserts as it should, except no file is uploaded to the server.

To be sure all required files are available i have linked to a sample zip file of the files i am working with.
http://www.collegecameras.co.uk/Error_Sample_Files_tNG_isFileInsideBaseFolder.zip

A working sample of the error can be found at http://www.collegecameras.co.uk/del.asp

Thanks again for any help you can give.
Rob
<%
	'KT_FileUpload__ 
	Dim KT_FileUpload__OlderFilesExpireTime: KT_FileUpload__OlderFilesExpireTime = 60 * 15 '  15 minutes
 
	If InStr(Request.ServerVariables("CONTENT_TYPE"), "multipart/form-data") Then
                ' If having problems saving UTF-8 characters into the database, you need to uncomment the following line 
                ' and replace 1252 with the code page that your server uses
                'Response.CodePage = 1252
		Session.Contents.Remove("KT_FileUpload__Error_U") ' user error
		Session.Contents.Remove("KT_FileUpload__Error_D") ' developer error
		Session.Contents.Remove("KT_FileUpload__UploadedFiles")
		Session.Contents.Remove("KT_FileUpload__Resubmit")
		
		Dim KT_FileUpload__Handler: Set KT_FileUpload__Handler = new FreeASPUpload
		KT_FileUpload__Handler.Upload
		
		Dim KT_FileUpload__tempFolder: KT_FileUpload__tempFolder = KT_FileUpload__GetAbsolutePathToTempFolder()
		If KT_FileUpload__tempFolder <> "" Then
			' save the files from the stream
			On Error Resume Next
			KT_FileUpload__Handler.Save KT_FileUpload__tempFolder
			If err.number <> 0 Then
				KT_FileUpload__setError "ASP_UPLOAD_ERR_STREAM_WRITE", Array(), Array(KT_FileUpload__tempFolder) 
		
				' the files couldn't be saved into temp folder, so remove them from UploadedFiles dict
				KT_FileUpload__Handler.UploadedFiles.removeAll
			End If
			On Error GoTo 0
			
			' delete older temporary uploaded files
			KT_FileUpload__RemoveOlderTempFiles KT_FileUpload__tempFolder
		Else
			' the files couldn't be saved into temp folder, so remove them from UploadedFiles dict
			KT_FileUpload__Handler.UploadedFiles.removeAll
		End If			
		
 
		Session("KT_FileUpload__Resubmit") = True
		Set Session("KT_FileUpload__UploadedFiles") = KT_FileUpload__Handler.GetUploadedFilesAsDictionary
		
		If IsEmpty (KT_RawRequest__NO_Resubmit) Then
			' Resubmit form
			Response.AddHeader "Pragma", "No-Cache"
			Response.CacheControl = "no-cache"
			Response.Expires = -1
			
			Response.write "<html><head><title>KT_FileUpload Resubmit</title></head>" & vbNewLine
			Response.write "<body onload=""javascript: document.forms.KT_fileUploadForm.submit()"">"  & vbNewLine
			Response.write "<form action="""" method=""post"" name=""KT_fileUploadForm"" enctype=""application/x-www-form-urlencoded"">"  & vbNewLine
                        ' If having problems saving UTF-8 characters into the database, you need to remove the Server.HTMLEncode function calls from the following lines
			' Form keys
			For each formKey in KT_FileUpload__Handler.FormElements
				For each multiKey in KT_FileUpload__Handler.FormElements(formKey)
					Response.write "<input type=""hidden"" name=""" & formKey & """ value=""" & Server.HTMLEncode(KT_FileUpload__Handler.FormElements(formKey)(multiKey)) & """ >" & vbNewLine
				Next
			Next
			' Files
			For each fileKey in KT_FileUpload__Handler.UploadedFiles
				Response.write "<input type=""hidden"" name=""" & fileKey & """ value=""" & Server.HTMLEncode(KT_FileUpload__Handler.UploadedFiles(fileKey).FileName) & """ >" & vbNewLine
			Next
			Response.write "<input name=""KT_FileUpload__Resubmit"" type=""hidden"" value=""True"">"
			Response.write "</form></body></html>"
			Response.End()
		Else
			' no resubmit is done / called from KTML4_SP
			ExecuteGlobal "Set KT_RawRequestForm = Server.CreateObject(""Scripting.Dictionary"")"
			' Form keys
			Set KT_RawRequestForm("FormElements") = Server.CreateObject("Scripting.Dictionary")
			For each formKey in KT_FileUpload__Handler.FormElements
				Set KT_RawRequestForm("FormElements")(formKey) = Server.CreateObject("Scripting.Dictionary")
				For each multiKey in KT_FileUpload__Handler.FormElements(formKey)
					KT_RawRequestForm("FormElements")(formKey)(multiKey) = KT_FileUpload__Handler.FormElements(formKey)(multiKey)
				Next
			Next
			' Files
			Set KT_RawRequestForm("UploadedFiles") = Server.CreateObject("Scripting.Dictionary")
			For each fileKey in KT_FileUpload__Handler.UploadedFiles
				KT_RawRequestForm("UploadedFiles")(fileKey) = KT_FileUpload__Handler.UploadedFiles(fileKey).FileName
			Next
		End If	
	Else
		If Request.Form("KT_FileUpload__Resubmit") = "True" Then
			If Session("KT_FileUpload__Resubmit") Then				
				Session("KT_FileUpload__Resubmit") = False
			Else
				Session.Contents.Remove("KT_FileUpload__Error_D")
				Session.Contents.Remove("KT_FileUpload__Error_U")
				Session.Contents.Remove("KT_FileUpload__UploadedFiles")
				Session.Contents.Remove("KT_FileUpload__Resubmit")			
				
				' refresh for the resubmit.. 
				Response.write "<html><head><title>KT_FileUpload Resubmit</title></head>" & vbNewLine
				Response.write "<body onload=""javascript: document.forms[0].submit()"">"  & vbNewLine
				Response.write "<form action="""" method=""post"" enctype=""application/x-www-form-urlencoded"">"  & vbNewLine
				Response.write "</form></body></html>"
				Response.End()
			End If	
		End If
	End If
 
 
'##########################################################################
' 	 Helper Functions 	
 
	' Save errors to Session
	Sub KT_FileUpload__setError (errorCode, arrArgsUsr, arrArgsDev)
		errorCodeDev = errorCode & "_D"
		
		Session("KT_FileUpload__Error_U") = KT_getResource(errorCode, "FileUpload", arrArgsUsr)
		Session("KT_FileUpload__Error_D") = KT_getResource(errorCodeDev, "FileUpload", arrArgsDev)
	End Sub
 
 
	' deletes older uploaded files from the temporary folder
	Private Sub KT_FileUpload__RemoveOlderTempFiles (pathToTempFolder)
		On error resume next
		Dim fso, fld, fc, f
		Set fso = Server.CreateObject("Scripting.FileSystemObject")
 
		Set fld = fso.GetFolder(pathToTempFolder)
		Set fc = fld.Files
		For Each f in fc
			DateCreated = Cdate(f.DateCreated)
			elapsed  = DateDiff("s", DateCreated, Now)
 
			If elapsed > KT_FileUpload__OlderFilesExpireTime Then
				f.Delete (true)
				If err.number<> 0 Then
					' do nothing if couldn't delete a file
					' missing full permissions on temp folder are caught somewhere else
					err.clear
					Exit For
				End If
			End If
		Next
		Set fso = nothing
		On error Goto 0
	End Sub
	
 
	Function KT_FileUpload__GetAbsolutePathToTempFolder()
		Dim absolutePathToRootFolder: absolutePathToRootFolder = KT_GetAbsolutePathToRootFolder()
		Dim relativePathToTempFolder: relativePathToTempFolder = "includes\common\lib\file_upload\Temp\"
		
		If absolutePathToRootFolder <> "" Then
			Dim fso: Set fso = Server.CreateObject("Scripting.FileSystemObject")
			On Error Resume Next
			If not fso.FolderExists(absolutePathToRootFolder & relativePathToTempFolder) Then
				fso.CreateFolder(absolutePathToRootFolder & relativePathToTempFolder)
			End If
			If Err.Number <> 0 Then
				KT_FileUpload__setError "ASP_UPLOAD_ERR_CREATE_TEMP", Array(), Array(absolutePathToRootFolder & relativePathToTempFolder)
				KT_FileUpload__GetAbsolutePathToTempFolder = ""
			Else
				KT_FileUpload__GetAbsolutePathToTempFolder = absolutePathToRootFolder & relativePathToTempFolder
			End If
			Set fso = nothing
			On Error GoTo 0
		Else
			KT_FileUpload__setError "ASP_UPLOAD_MISSING_TEMP", Array(), Array(absolutePathToRootFolder & relativePathToTempFolder) 
		End If
	End Function
 
 
 
 
'##########################################################################
 
' For examples, documentation, and your own free copy, go to:
' http://www.freeaspupload.net
' Note: You can copy and use this script for free and you can make changes
' to the code, but you cannot remove the above comment.
 
 Class FreeASPUpload
	  Public UploadedFiles
	  Public FormElements
	
	  Private VarArrayBinRequest
	  Private StreamRequest
	  Private uploadedYet
	
	  Private Sub Class_Initialize()
		Set UploadedFiles 	= Server.CreateObject("Scripting.Dictionary")
		Set FormElements 	= Server.CreateObject("Scripting.Dictionary")
		Set StreamRequest 	= Server.CreateObject("ADODB.Stream")
		StreamRequest.Type 	= 1 'adTypeBinary
		StreamRequest.Open
		uploadedYet = false
	  End Sub
	  
	  Private Sub Class_Terminate()
		If IsObject(UploadedFiles) Then
		  UploadedFiles.RemoveAll()
		  Set UploadedFiles = Nothing
		End If
		If IsObject(FormElements) Then
		  FormElements.RemoveAll()
		  Set FormElements = Nothing
		End If
		StreamRequest.Close
		Set StreamRequest = Nothing
	  End Sub
	
	  Public Function GetUploadedFilesAsDictionary()
	  		Dim dict: Set dict = Server.CreateObject("Scripting.Dictionary")
			For each f in UploadedFiles
				Set dict(f) = UploadedFiles(f).GetUploadedFileAsDictionary
			Next
			Set GetUploadedFilesAsDictionary = dict
	  End Function
	
	  Public Property Get Form(sIndex)
		Form = ""
		If FormElements.Exists(LCase(sIndex)) Then Form = FormElements.Item(LCase(sIndex))
	  End Property
	
	  Public Property Get Files()
		Files = UploadedFiles.Items
	  End Property
	
	  'Calls Upload to extract the data from the binary request and then saves the uploaded files
	  Public Sub Save(path)
		Dim streamFile, fileItem
	
		if Right(path, 1) <> "\" then path = path & "\"
	
		if not uploadedYet then Upload
	
		For Each fileItem In UploadedFiles.Items
			If fileItem.FileName <> "" Then
				Set streamFile = Server.CreateObject("ADODB.Stream")
				streamFile.Type = 1
				streamFile.Open
				StreamRequest.Position = fileItem.Start
				StreamRequest.CopyTo streamFile, fileItem.Length
				streamFile.SaveToFile path & fileItem.TempFileName, 2
				streamFile.close
				Set streamFile = Nothing
				fileItem.Path = path & fileItem.TempFileName
			End If	
		 Next
	  End Sub
	
	  Public Function SaveBinRequest(path) ' For debugging purposes
	  	StreamRequest.Write Request.BinaryRead(Request.TotalBytes)
		StreamRequest.SaveToFile path, 2
		Response.End()
	  End Function
	
	  Public Sub DumpData() 
		Dim i, aKeys, f
		response.write "<b>Form Items:</b><br>"
		aKeys = FormElements.Keys
		For i = 0 To FormElements.Count -1 ' Iterate the array
	  	    response.write aKeys(i) & " = <br>"
		  	For each k in FormElements(aKeys(i)) 
				Response.write "&nbsp;&nbsp;&nbsp;&nbsp;" & FormElements(aKeys(i))(k) & "<BR>"
			 Next
		Next
		response.write "<b>Uploaded Files:</b><br>"
		For Each f In UploadedFiles.Items
		  response.write "Name: " & f.FileName & "<br>"
		  response.write "TempName: " & f.TempFileName & "<br>"
		  response.write "Type: " & f.ContentType & "<br>"
		  response.write "Start: " & f.Start & "<br>"
		  response.write "Size: " & f.Length & "<br>"
		 Next
	  End Sub
	
	  Public Sub Upload()
		Dim nCurPos, nDataBoundPos, nLastSepPos
		Dim nPosFile, nPosBound
		Dim sFieldName, osPathSep, auxStr
	
		'RFC1867 Tokens
		Dim vDataSep
		Dim tNewLine, tDoubleQuotes, tTerm, tFilename, tName, tContentDisp, tContentType
		tNewLine = Byte2String(Chr(13))
		tDoubleQuotes = Byte2String(Chr(34))
		tTerm = Byte2String("--")
		tFilename = Byte2String("filename=""")
		tName = Byte2String("name=""")
		tContentDisp = Byte2String("Content-Disposition")
		tContentType = Byte2String("Content-Type:")
	
		uploadedYet = true
	
		on error resume next
		VarArrayBinRequest = Request.BinaryRead(Request.TotalBytes)
		if Err.Number <> 0 then 
			error = Err.Description
			KT_FileUpload__setError "ASP_UPLOAD_ERR_BINARY_READ", Array(), Array(error) 
			'Response.Write Session("KT_FileUpload__Error_D")
			'Response.End
			' maybe  I should print the error and stop the execution
			on error goto 0
			Exit Sub
		end if
		on error goto 0 'reset error handling
		
		nCurPos = FindToken(tNewLine,1) 'Note: nCurPos is 1-based (and so is InstrB, MidB, etc)
	
		If nCurPos <= 1 Then Exit Sub
		 
		'vDataSep is a separator like -----------------------------21763138716045
		vDataSep = MidB(VarArrayBinRequest, 1, nCurPos-1)
	
		'Start of current separator
		nDataBoundPos = 1
	
		'Beginning of last line
		nLastSepPos = FindToken(vDataSep & tTerm, 1)
	
		Do Until nDataBoundPos = nLastSepPos
 		  nCurPos = SkipToken(tContentDisp, nDataBoundPos)
		  If nCurPos = -1 Then
		  	Exit Do
		  End If
		  nCurPos = SkipToken(tName, nCurPos)
		  sFieldName = ExtractField(tDoubleQuotes, nCurPos)
	
		  nPosFile = FindToken(tFilename, nCurPos)
		  nPosBound = FindToken(vDataSep, nCurPos)
		  
		  If nPosFile <> 0 And nPosFile < nPosBound Then
			Dim oUploadFile
			Set oUploadFile = New UploadedFile
			
			nCurPos = SkipToken(tFilename, nCurPos)
			auxStr = ExtractField(tDoubleQuotes, nCurPos)
			' We are interested only in the name of the file, not the whole path
			' Path separator is \ in windows, / in UNIX
			' While IE seems to put the whole pathname in the stream, Mozilla seem to 
			' only put the actual file name, so UNIX paths may be rare. But not impossible.
			osPathSep = "\"
			if InStr(auxStr, osPathSep) = 0 then osPathSep = "/"
			oUploadFile.FileName = Right(auxStr, Len(auxStr)-InStrRev(auxStr, osPathSep))
	
			if (Len(oUploadFile.FileName) > 0) then 'File field not left empty
			   nCurPos = SkipToken(tContentType, nCurPos)
			  
			   auxStr = ExtractField(tNewLine, nCurPos)
				' NN on UNIX puts things like this in the streaa:
				' ?? python py type=?? python application/x-python
			   oUploadFile.ContentType = Right(auxStr, Len(auxStr)-InStrRev(auxStr, " "))
			   nCurPos = FindToken(tNewLine, nCurPos) + 4 'skip empty line
			  
			   oUploadFile.Start = nCurPos-1
			   oUploadFile.Length = FindToken(vDataSep, nCurPos) - 2 - nCurPos
			   oUploadFile.SetTempFileName
			Else
			   oUploadFile.Start = -1
			   oUploadFile.Length = 0
			End If  
			   'If oUploadFile.Length > 0 Then Set UploadedFiles(sFieldName) = oUploadFile
			   Set UploadedFiles(sFieldName) = oUploadFile
			
		  Else
			Dim nEndOfData
			nCurPos = FindToken(tNewLine, nCurPos) + 4 'skip empty line
			nEndOfData = FindToken(vDataSep, nCurPos) - 2
			If Not FormElements.Exists(sFieldName) Then 
				Dim multipleValues: Set multipleValues = Server.CreateObject("Scripting.Dictionary")
				multipleValues.Add 0, String2Byte(MidB(VarArrayBinRequest, nCurPos, nEndOfData-nCurPos))
				Set FormElements(sFieldName) = multipleValues
			Else
				FormElements(sFieldName).Add FormElements(sFieldName).Count, String2Byte(MidB(VarArrayBinRequest, nCurPos, nEndOfData-nCurPos))	
			End If	
		  End If
	
		  'Advance to next separator
		  nDataBoundPos = FindToken(vDataSep, nCurPos)
		Loop
		StreamRequest.Write(VarArrayBinRequest)
	  End Sub
	
	  Private Function SkipToken(sToken, nStart)
		SkipToken = InstrB(nStart, VarArrayBinRequest, sToken)
		If SkipToken = 0 then	
			SkipToken = -1
			Exit Function
		end if
		SkipToken = SkipToken + LenB(sToken)
	  End Function
	
	  Private Function FindToken(sToken, nStart)
		FindToken = InstrB(nStart, VarArrayBinRequest, sToken)
	  End Function
	
	  Private Function ExtractField(sToken, nStart)
		Dim nEnd
		nEnd = InstrB(nStart, VarArrayBinRequest, sToken)
		If nEnd = 0 then
		 ' Exception thrown
		  Response.write "Error in parsing uploaded binary request."
		  Response.End
		end if
		ExtractField = String2Byte(MidB(VarArrayBinRequest, nStart, nEnd-nStart))
	  End Function
	
	  'String to byte string conversion
	  Private Function Byte2String(sString)
		Dim i
		For i = 1 to Len(sString)
		 Byte2String = Byte2String & ChrB(AscB(Mid(sString,i,1)))
		Next
	  End Function
	
	  'Byte string to string conversion
	  Private Function String2Byte(bsString)
		Dim i
		String2Byte =""
		For i = 1 to LenB(bsString)
		 String2Byte = String2Byte & Chr(AscB(MidB(bsString,i,1))) 
		Next
	  End Function
 	End Class
 
 
	Class UploadedFile
		Public ContentType
		Public Start
		Public Length
		Public Path
		Private nameOfFile
		Private tmpNameOfFile
		
		' Need to remove characters that are valid in UNIX, but not in Windows
		Public Property Let FileName(fN)
		nameOfFile = fN
		nameOfFile = replace(nameOfFile, "\", "_")
		nameOfFile = replace(nameOfFile, "/", "_")
		nameOfFile = replace(nameOfFile, ":", "_")
		nameOfFile = replace(nameOfFile, "*", "_")
		nameOfFile = replace(nameOfFile, "?", "_")
		nameOfFile = replace(nameOfFile, """", "_")
		nameOfFile = replace(nameOfFile, "<", "_")
		nameOfFile = replace(nameOfFile, ">", "_")
		nameOfFile = replace(nameOfFile, "|", "_")
		nameOfFile = replace(nameOfFile, "..", "_")		
		End Property
 
		Public Property Get FileName()
			FileName = nameOfFile
		End Property
		
		Public Sub SetTempFileName()
			' build a unique temp file name
			' unique per session / per time of execution / per position in the submitted stream
			
			'tmpNameOfFile = Session.SessionID & "_" & Replace(Cstr(Timer),".","") & "_" & left(Start & "000000", 6)
			
			Dim fso: Set fso = Server.CreateObject("Scripting.FileSystemObject")
			tmpNameOfFile = fso.GetTempName
			Set fso = nothing
		End Sub
		
		Public Property Get TempFileName()
			TempFileName = tmpNameOfFile
		End Property
		
		Public Property Get FileExtension()
			FileExtension = ""
			If nameOfFile <> "" Then
				If instrrev(nameOfFile, ".") <> 0 Then
					FileExtension = mid(nameOfFile, instrrev(nameOfFile,".")+1)
				End If
			End If
		End Property
		
		Public Function GetUploadedFileAsDictionary
			Dim upDict: Set upDict = Server.CreateObject ("Scripting.Dictionary")
			upDict.Add "ContentType", ContentType
			upDict.Add "Length", Length
			upDict.Add "Path", Path
			upDict.Add "FileName", FileName
			upDict.Add "FileExtension", FileExtension
			upDict.Add "TempFileName", TempFileName
			Set GetUploadedFileAsDictionary = upDict
		End Function
	End Class
 
%>

Open in new window

0
 
RouchieCommented:
I'm afraid there is far too much code contained in the ZIP file to be able to decipher for you.  Looking online it seems you are not the only one to receive this error, and the requests for help seem to go largely unanswered.  As Adobe has discontinued support for this product it could be safe to say that it wasn't worth the stress for them to maintain it, which means you should find an alternative upload product such as  http://www.freeaspupload.net/

I could not find the tNG_isFileInsideBaseFolder function using a Windows text search on the zipped files, but then Windows text search has a habit of looking for the whole word rather than an occurrence of the string.  

Try using DW's internal search to see if you can find tNG_isFileInsideBaseFolder.  If it doesn't exist then there are definitely problems with the coding package.  I am sure that the function wil exist somewhere in one of the include files because ASP would throw an error about the function not existing otherwise.
0
 
ticallianAuthor Commented:
I've used DW to search the entire site for "tNG_isFileInsideBaseFolder" with Match Case off and Whitespacing ignored but there are only the two occurences as stated in my post above, during the insert and the delete image files.

I'm going to have a try at the freeaspupload.net option and see how that works out.

Thanks again for your time.
0
 
ticallianAuthor Commented:
I've managed to solve the problem.

I created a new site within DW and recreated the upload page using Adobe ADDT. I then tried to search the new Include files for the function "tNG_isFileInsideBaseFolder" and it turned up in the file "tNG_functions.inc.asp", i replaced this lone file into my other site and it then worked fine.

I don't know how or when this file was changed but my recommendation to anyone else is just follow the steps above.

Note: ADDT's "Update Include Folder" did not repair this file when updated.
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now