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

VB5/CGI/uploading binary files

Hello,

I want to use an HTML form to have a user of the form be able to upload a binary file and then send it to a CGI script. The CGI script will save this file in the cgibin directory(so if this is a .exe file, the script will save  it to the disk as something.exe. If it is a .gif file, it will save it to the disk as something.gif, etc.).  I am using the cgi32.bas module.  
The problem that I am having is that I'm not sure how to put the file data in to a file after it is submitted. "cgi32.bas" has  the "getsmallfield" function to get fields submitted through a form, but as the name says it, it only "gets" small amounts of data. Also, it returns data as string elements and not as binary (I'm not sure if this makes a difference).
The HTML code that I'm planning to use is at the bottom. Basically, it allows the user of the form to browse his hard drive and to select a file he wants to submit.

<FORM action="processfile.exe" enctype="multipart/form-data" method="Post">
    Location: <INPUT name="fileupload" type="file" size=30>
    <INPUT type="submit" value="Send">
</FORM>
0
pizarro
Asked:
pizarro
  • 2
  • 2
1 Solution
 
gwaltersCommented:
I can't help you with the VB part, but I would imagine that getsmallfield is intended for x-www-form-urlencoded format, not for the multipart/form-data that's required to have an input of type=file.

Try reading from stdin (I assume this can be done in VB).  You should get a MIME-like message.  Each part will be a variable from the form (one of them will be the file they uploaded).

0
 
pizarroAuthor Commented:
Thanks for your comments,
I already tried doing, but I want to do this for an already existing script.  Therefore, I'd like to avoid having to change the whole thing by getting rid of cgi32.bas (which is what is suggest in more or less words).
0
 
gwaltersCommented:
Well, if cgi32.bas doesn't support multipart/form-data, then you have no choice.
0
 
alamoCommented:
Ok, after getting off on the wrong track in the other instance of this question which you posted, I did some research into cgi32.bas and I think I can answer your question.

cgi32.bas is an interface between a VB program and a server (such as Website) which uses the WinCGI interface. WinCGI uses files rather than stdin/stdout/environment to pass information between server and CGI program.

You didn't specify your server. Apparently servers which support WinCGI will auto-decode uploaded file data. Accordingly, cgi32.bas has the following globals:

Global CGI_FileTuples(MAX_FILE_TUPLES) As FileTuple ' File upload tuples
Global CGI_NumFileTuples As Integer             ' # of live entries in array
Type FileTuple              ' Used for form-based file uploads
    key As String           ' Form field name
    file As String          ' Local tempfile containing uploaded file
    length As Long          ' Length in bytes of uploaded file
    type As String          ' Content type of uploaded file
    encoding As String      ' Content-transfer encoding of uploaded file
    name As String          ' Original name of uploaded file
End Type

So the upshot of this is when a user uploads a file to you, CGI_FileTuples(0).file is the name of the temporary file which holds the uploaded file, and CGI_FileTuples(0).name is the original name of the uploaded file. So to move the uploaded file to its final destination on your server just rename it -

Name CGI_FileTuples(0).file as (whatever)

Will this work with your particular server and will all uploads? Don't know for certain, but definitely worth a try. If it doesn't work be sure to tell us what the server version is, that might make a big difference.
0
 
pizarroAuthor Commented:
Excellent answer.  I should have examined cgi32.bas before asking the question.
 
thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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