FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


upload file to server using html form and CGI C





lightwate
Hi all! I need to make a site that can upload a picture to a server via cgi script. The script needs to be written in C.

I just started learning this earlier today. I already made the html form send the file via POST, but all i can read are encrypted stuff. Does anyone know how I can decode this and how I can save the file to the server?

Here is my code so far...

for the html:
Code:
<form action="uploadtest.cgi" method="POST" enctype="multipart/form-data" >
   <fieldset><legend>Upload</legend>
   <!---<input name="myinput" />//-->
   <input type="file" name="myFile" />
   </fieldset>
   <input type="submit"  value="Submit" />
</form>


for the cgi:
Code:
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   puts("Content-type:text/html\n\n");/* This is required */
   puts("<html><body>");
   
   char *data;
   data = getenv("CONTENT_LENGTH");
   int size;
   size = atoi(data);
      printf("size: %d<br>", size);
   
   char input[100000];
   fgets(input, 999, stdin);
   puts(input);

   puts("</body></html>");
return 0;
}   


I don't know the whole concept about this file uploading thing. And we're not allowed to use non-standart libraries.
lightwate
By the way, when attempting to upload a picture using the form, the cgi script outputs this:

size: 6681
------WebKitFormBoundaryO3FLpXVTYU08lKzN
saberlivre
The form contains files data which are submitted in content-type "multipart/form-data".
Perhaps you will find more information at
http://libccgi.sourceforge.net/doc.html
Related topics
Can someone make me a php script?
Simulating the back button
So is everyone here using HTML coding???
HTML form, list of options or text input
Send Mail HTML Form
Upload file
image upload, and return url to image
How do i password protect a web page using html
Need Help, how to transfer to files to server using $_GET
HTTP Fileupload and CHMOD
TMP File Problem
Help needed with getting table to auto update via html form
File Server and Resource Manager (Part 2)
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.