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