Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB5/CGI/uploading binary files

Posted on 1997-10-24
5
Medium Priority
?
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 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