Solved

VB5/CGI/uploading binary files

Posted on 1997-10-24
5
236 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 100 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now