Skip to content

Read Content-Type header to a text file #62

@ghost

Description

`#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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions