fcgi2
fcgi2 copied to clipboard
Obtain file data via FCGI_fread
`#include <fcgi_stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h>
int main(void)
{
int count = 1;
while(FCGI_Accept() >= 0) {
char *contentLength = getenv("CONTENT_LENGTH");
int len;
if (contentLength != NULL) {
len = strtol(contentLength, NULL, 10);
}
else {
len = 0;
}
printf("Content-type: text/html\r\n"
"\r\n"
"
FastCGI Hello!
" "Request number %d running on host %s\n", count++, getenv("SERVER_NAME")); printf("<br />CONTENT_LENGTH = %d <br />\r\n", len);
printf("<form enctype='multipart/form-data' method='post' action='?'><input type='text' name='text1' /><input type='file' name='file1'/><input type='submit' /></form>");
printf("<hr />");
fflush(stdout);
char *rawBuffer = (char*)malloc(sizeof(char [len]));
FCGI_fread(rawBuffer, len, 1, FCGI_stdin);
FILE * fileOut = fopen("/tmp/fcgi.out", "a");
fprintf(fileOut, "%s", rawBuffer);
fclose(fileOut);
FCGI_Finish();
}
} ` Could you explain, please, why this code did not write to the fcgi.out file?
your seem to not be good... you execute every time the read from stdin.... normaly you need to have if that print the form or read the stdin...