"Fossies" - the Fresh Open Source Software Archive

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


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <stdlib.h>
    2 #include <stdio.h>
    3 #include "gcgi.h"
    4 
    5 static const char* const strTypes[] = {
    6     "text", 
    7     "image", 
    8     "audio", 
    9     "video", 
   10     "application", 
   11     "multipart", 
   12     "message", 
   13     "unknown"
   14 };
   15 
   16 static const char* const strEncodings[] = {
   17     "7bit", 
   18     "8bit", 
   19     "binary", 
   20     "quoted-printable", 
   21     "base64", 
   22     "unknown"
   23 };
   24 
   25 int main (int argc, char *argv[], char *envp[]) 
   26 {
   27   MimeEncoding  enc;
   28   MimeType      type;
   29   char         *file, *fname, *subtype; 
   30   int           len, truncated;
   31 
   32   gcgiDebug("./gcgi-env", "./file-upload-example-unix.txt");
   33   
   34   /* Set Limits: field limit, query limit */
   35   gcgiSetLimits(1048576, 0);
   36 
   37   if (initCgi() < 0) {
   38     fprintf(stderr, "Unable to parse CGI query.\n");
   39     return -1;
   40   }
   41   
   42   //gcgiSaveEnvVariables("/tmp/gcgi-env");
   43 
   44   gcgiFieldSize("uploaded_file", &len);
   45   file = (char *) malloc(len);
   46 
   47   gcgiFetchData("uploaded_file", file, len, &type, &subtype, &enc, &fname, &truncated);
   48 
   49   if (truncated) {
   50     fprintf(gcgiOut, "Content-Type: text/plain\r\n\r\n");
   51     fprintf(gcgiOut, "File size has exceeded limit.  Pick something smaller.\n");
   52   }
   53   else {
   54     fprintf(gcgiOut,"Content-Type: %s/%s\r\n", strTypes[type], subtype);
   55     fprintf(gcgiOut,"Content-Disposition: attachment; filename=\"%s\"\r\n", fname);
   56     fprintf(gcgiOut,"Content-Length: %d\r\n\r\n", len);
   57 
   58     fprintf(stderr,"Content-Type: %s/%s\r\n", strTypes[type], subtype);
   59     fprintf(stderr,"Content-Disposition: attachment; filename=\"%s\"\r\n", fname);
   60     fprintf(stderr,"Content-Length: %d\r\n\r\n", len);
   61 
   62     fwrite(file, sizeof(char), len, gcgiOut);
   63   }
   64 
   65   free(file);
   66   free(subtype);
   67   free(fname);
   68 
   69   freeCgi();
   70 
   71   return 0;
   72 }