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

Read Content-Type header to a text file #62

Open
ghost opened this issue Nov 11, 2022 · 0 comments
Open

Read Content-Type header to a text file #62

ghost opened this issue Nov 11, 2022 · 0 comments

Comments

@ghost
Copy link

ghost commented Nov 11, 2022

`#include <fcgi_stdio.h>
#include <stdlib.h>

int main(void)
{

int len = 0;
while(FCGI_Accept() >= 0) {
FILE * fp = fopen("/wwwdata/example.txt", "w+");
char *content_type = getenv("CONTENT_TYPE");
char *contentLength = getenv("CONTENT_LENGTH");

    if (contentLength != NULL) 
        len = atoi(contentLength);            
    else 
        len = 0;        
    
    printf("Content-type: text/html\r\n"
           "\r\n"
           "<!DOCTYPE html><html><head><meta content='text/html;charset=utf-8' http-equiv='Content-Type'><meta charset='utf-8' http-equiv='encoding'><script type='text/javascript'>"
           "function f(){var x = new XMLHttpRequest();x.open('POST', '/i/a.out', true);x.timeout = 300000;"
    		"var f = new FormData();"
    		"f.append('f', window.document.getElementById('f').files[0]);"
    		"x.send(f);"
           "}</script></head><body>"
	       "<b>%d</b><input type='file' id='f' name='f' accept='image/png'><p onClick='f();'>PRESS!</p></body></html>\n"
           ,len);
  
	if (len > 0 && content_type != NULL)
		for(int i = 0; i < len; i++)
			putc(content_type[i], fp);
	

    fclose(fp);
    FCGI_Finish();
}    

}
`
Hi!
I'm trying to read this environment variable and write it to the file. I have loaded PNG and output is 120KB but text editor marks it as a non-text file. Why? How to solve it?

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

0 participants