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

How to

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

Upload a file while maintaining the original filename

Keywords: 




;***************************************************************************
;** 
;** Upload.web - Bill Meek 071502
;** 
;** Purpose: Upload a file while maintaining the original filename
;** Inputs: upload.htm
;** Outputs: A single file in the current folder
;** Revisions: 
;***************************************************************************

mydir="C:\Program Files\WebBatch\upload\"
DirChange(mydir)

WebOut( 'Content-type: text/html', 2)
WebOut( '<html> <head> <title>Upload Example</title> </head> <body>', 1)

;get the size of the file
wfs=WebParamSize("upl-file")
;buffer to hold the file
binbuf=BinaryAlloc(wfs)
;oversized buffer to hold the file with header info
binbuf2=BinaryAlloc(wfs+5000)

;get the *unparsed* cotents of the form fields
WebConBuf(binbuf2)
startfn=BinaryIndexEx(binbuf2, 0, 'filename=', @FWDSCAN, @FALSE)+10
endfn=BinaryIndexEx(binbuf2, startfn, '"', @FWDSCAN, @FALSE)
fullfilepath=BinaryPeekStr(binbuf2, startfn, endfn-startfn)
filename=StrCat(FileRoot(fullfilepath),".",FileExtension(fullfilepath))

;get the *parsed* cotents of the form field
WebParamBuf("upl-file", binbuf)
BinaryWrite(binbuf, filename)

BinaryFree(binbuf2)
BinaryFree(binbuf)

WebOut( '</body>', 1)
WebOut( '</html>', 1)
;Save the next part as Upload.htm
<form enctype="multipart/form-data" method="post" action="/webcgi/webbatch.exe?upload/upload.web">
<input type=file name="upl-file" size=80>         
<input type=submit value="Upload File">
</form>


Article ID:   W15372
File Created: 2004:02:20:15:01:44
Last Updated: 2004:02:20:15:01:44