"Fossies" - the Fresh Open Source Software Archive

Member "libgcgi.a-0.9.5/examples/fileupload.html" (22 Jun 2002, 2426 Bytes) of package /linux/www/old/gcgi-0.9.5.tar.gz:


The requested HTML page contains a <FORM> tag that is unusable on "Fossies" in "automatic" (rendered) mode so that page is shown as HTML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    2 <html>
    3   <head>
    4     <title>GCGI File Upload Test</title>
    5   </head>
    6 
    7   <body>
    8     <h1>GCGI File Upload Test</h1>
    9     <p>
   10       The following GCGI test program will upload the file you specify, and then immediatley send it 
   11       back to your browser.  If you upload an image or text file, the browser will display them, if
   12       you upload anything else, your browser should prompt you to save it to your local machine.
   13     </p>
   14     <form method="POST" enctype="multipart/form-data" action="http://topeka.shingletowngap.org/cgi-bin/gcgiFileUploadTest">
   15       <p>File Upload: <input type=file name="uploaded_file" size="50">
   16       </p>
   17       <input type=submit>
   18     </form>
   19 
   20     <p>
   21       Here is the code to make this happen:
   22 
   23       <pre>
   24 #include &lt;stdlib.h&gt;
   25 #include &lt;stdio.h&gt;
   26 #include "gcgi.h"
   27 
   28 const char* const strTypes[] = {
   29     "text", 
   30     "image", 
   31     "audio", 
   32     "video", 
   33     "application", 
   34     "multipart", 
   35     "message", 
   36     "unknown"
   37 };
   38 
   39 const char* const strEncodings[] = {
   40     "7bit", 
   41     "8bit", 
   42     "binary", 
   43     "quoted-printable", 
   44     "base64", 
   45     "unknown"
   46 };
   47 
   48 int main (int argc, char *argv[], char *envp[]) 
   49 {
   50   MimeEncoding  enc;
   51   MimeType      type;
   52   char         *file, *fname, *subtype;
   53   int           len;
   54 
   55    /* Set Limits: field limit, query limit */
   56   gcgiSetLimits(1048576, 0);
   57 
   58   if (initCgi() < 0) {
   59     fprintf(stderr, "Unable to parse CGI query.\n");
   60     return -1;
   61   }
   62 
   63   gcgiFieldSize("uploaded_file", &len);
   64   file = (char *) malloc(len);
   65 
   66   gcgiFetchData("uploaded_file", file, len, &type, &subtype, &enc, &fname, &truncated);
   67 
   68   if (truncated) {
   69     fprintf(gcgiOut, "Content-Type: text/plain\r\n\r\n");
   70     fprintf(gcgiOut, "File size has exceeded limit.  Pick something smaller.\n");
   71   }
   72   else {
   73     fprintf(gcgiOut,"Content-Type: %s/%s\r\n", strTypes[type], subtype);
   74     fprintf(gcgiOut,"Content-Disposition: attachment; filename=\"%s\"\r\n", fname);
   75     fprintf(gcgiOut,"Content-Length: %d\r\n\r\n", len);
   76 
   77     fwrite(file, sizeof(char), len, gcgiOut);
   78   }
   79 
   80   free(file);
   81   free(subtype);
   82   free(fname);
   83 
   84   freeCgi();
   85 
   86   return 0;
   87 }
   88       </pre>
   89     </p>
   90     <hr>
   91     <address><a href="mailto:catchen@topeka.rebelalliance.org">Julian M Catchen</a></address>
   92 <!-- Created: Tue Jul 31 18:39:05 MST 2001 -->
   93 <!-- hhmts start -->
   94 Last modified: Sun Mar 24 11:32:40 MST 2002
   95 <!-- hhmts end -->
   96   </body>
   97 </html>