×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Uploading Binary Files

Uploading Binary Files

Uploading Binary Files

(OP)
Hello, I'm relatively new to CGI programming. I just finished several routines learning how to parse query strings. (Coded in straight C.) Now I'm trying to learn about multipart/form-data. I thew together a quick HTML form with some text fields and a file upload button and attached a simple text file and hit submit. My CGI simply does a text dump, so I see the boundary-separated info, including the file contents. But when I try try to upload anything besides a text file, something hangs. I never see the output. I don't think it's my CGI, but it seems to be sensitive to file extensions. I took my file "stuff.txt" (which uploaded successfully), renamed the extension: "stuff.abc", and the form hangs. I actually have to reboot my server to fix it. I can't find anything in my server settings that pertain to this. Any help is appreciated!

RE: Uploading Binary Files

(OP)
So it doesn't just seem to be binary files. I originally tested this with a very small text file (< 100 bytes). Then, I tried it with a slightly larger text file (100 - 200 bytes). It hangs. My CGI is just a text dump:

CODE --> C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>

int main(void)
{
	int n,check;

	printf("Content-Type: text/plain; charset=UTF-8\n\n");

	check=setmode(fileno(stdin), O_BINARY);
	if(check==-1){
		puts("setmode() error!");
		return 1;
	}
	while((n=fgetc(stdin))!=EOF)
		fputc(n,stdout);

	return 0;
} 

So, I just tried making an in-between-size file - about 80 bytes. The CGI only displays part of it??

RE: Uploading Binary Files

(OP)
Ok, so I thought I would try dumping the info to a file instead of stdout.

CODE --> C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>

int main(void)
{
	int n,check;
        FILE *td;

	printf("Content-Type: text/plain; charset=UTF-8\n\n");

	td=fopen("textdump.txt","wt");
	if(td==NULL){
		puts("Cannot create 'textdump' file!");
		return 1;
	}
	check=setmode(fileno(stdin), O_BINARY);
	if(check==-1){
		puts("setmode() error!");
		return 1;
	}
	while((n=fgetc(stdin))!=EOF)
		fputc(n,td);

        fclose(td);
	return 0;
} 

And everything worked fine (even though I changed stdin to binary and am writing to a text file). The text file has all the form info.
So the problem seems to have been writing to stdout. But why? What is causing output to the browser client area to get "bogged down" if that's even what's happening?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close