Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtain file data via FCGI_fread #59

Open
ghost opened this issue Aug 23, 2022 · 1 comment
Open

Obtain file data via FCGI_fread #59

ghost opened this issue Aug 23, 2022 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 23, 2022

`#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"
"<title>FastCGI Hello!</title>"
"

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?

@mcarbonneaux
Copy link
Member

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant