Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB5/CGI/uploading binary files

Posted on 1997-10-24
5
Medium Priority
?
250 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>
0
Comment
Question by:pizarro
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:gwalters
ID: 1831004
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
 

Author Comment

by:pizarro
ID: 1831005
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
 
LVL 3

Expert Comment

by:gwalters
ID: 1831006
Well, if cgi32.bas doesn't support multipart/form-data, then you have no choice.
0
 
LVL 6

Accepted Solution

by:
alamo earned 400 total points
ID: 1831007
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
 

Author Comment

by:pizarro
ID: 1831008
Excellent answer.  I should have examined cgi32.bas before asking the question.
 
thanks.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question