We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

VB5/CGI/uploading binary files

pizarro
pizarro asked
on
Medium Priority
271 Views
Last Modified: 2013-12-25
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>
Comment
Watch Question

Commented:
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).

Author

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).

Commented:
Well, if cgi32.bas doesn't support multipart/form-data, then you have no choice.
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Excellent answer.  I should have examined cgi32.bas before asking the question.
 
thanks.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.