WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WebBatch
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Sample Code to Return the Filename Associated with a FORM type="file" Variable

Keywords: 

WebBatch does not have a native function to return the filename associated with a FORM type="file" variable, it simply gives you the files contents. This function returns the original filename from the uploader's computer and returns this string.

May fail for some old text-only browsers (Lynx) that do not supply filenames.

Returns @FALSE if no file was specified

;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#DefineFunction udf_GetUploadFileName()
; this_dir=DirGet()
; DebugTrace(@ON, StrCat(this_dir, "webbatch_debug_GetUploadFileName.txt"))

;; Buffer the Multi-part form info.
bbsize=WebConSize()
binbuf=BinaryAlloc(bbsize)
WebConBuf(binbuf)
index = BinaryIndex(binbuf, 0, "Content-Type:", @FWDSCAN ) ;; Find the position of "Content-Type:"

;; Use index for content-type, scan back until the filename=" and then extract the text in between.
If (index>0)
fnindex = BinaryIndex( binbuf, index, "filename=", @BACKSCAN)
linelength = index-fnindex
;; Crop off 'filename="' from initial position with +10 and remove the '"@CRLF' from the end with -13
linedata=BinaryPeekStr(binbuf, fnindex+10, linelength-13) 
Else
linedata=@FALSE
Endif

binbuf=BinaryFree(binbuf)
Return linedata

#EndFunction 

Article ID:   W15370
File Created: 2010:02:17:10:58:08
Last Updated: 2003:05:13:10:27:20