trying to read a file using cgi scripting and C
i have a flex interface ...
I have a program that reads data from standard in and writes to a file..
Very simple. The problem is..
when i try to access the file with a url the .jpg file gives me trash and not the picture...
I am not exactly sure what i am doing wrong.. I have 2 post...
i will use the code tag for both...
The info in the image file...
Code:
# more /opt/moneylikes/tmp/*
::::::::::::::
/opt/moneylikes/tmp/file
::::::::::::::
------------cH2gL6gL6GI3KM7ei4ae0gL6KM7ae0
Content-Disposition: form-data; name="Filename"
Botanical Garden 239.JPG
------------cH2gL6gL6GI3KM7ei4ae0gL6KM7ae0
Content-Disposition: form-data; name="Filedata"; filename="Botanical Garden 239.JPG"
Content-Type: application/octet-stream
ÿØÿáPHExifMM*
(1âi ^L^LE8ê
# mv /opt/moneylikes/tmp/file /opt/moneylikes/tmp/file.jpg
# more /opt/moneylikes/tmp/*
------------cH2KM7Ij5Ef1ae0cH2ae0KM7ei4Ef1
Content-Disposition: form-data; name="Filename"
Botanical Garden 239.JPG
------------cH2KM7Ij5Ef1ae0cH2ae0KM7ei4Ef1
Content-Disposition: form-data; name="Filedata"; filename="Botanical Garden 239.JPG"
Content-Type: application/octet-stream
ÿØÿáPHExifMM*
(1âi ^L^LE8ê
EASTMAN KODAK COMPANYKODAK EASYSHARE C613 ZOOM DIGITAL CAMERAààKODAK EASYSHARE C613 ZOOM DIGITAL CAMERA'òú"'0221
*2
:B
J|1¸R..0100....
àÁ..9îhiµ..E«1¥½PÛÆzqâ¬çN+ùR¨Ó±/a¸Tr1..Hä)LJÉõíS®[jJÈH¤eÚÙ"æ¢þ2I¢z½'È9Å>$Ó ÏøÁíÅJØwIjlÒ¤òÀÆ
Ön¸ÏÖpx5<²±¹Ç8¨BHÍY·ÿZ£tQ,Ð..)Û*HÛp¤d,ÀqR*m&ÔÖWHW;Fìtõ¨Ä¥»T¯ÓßAQM4FIÁ
5Hî#}sZE«398ó7UòsÇ..Y##ØÔ~W4àÒZ$õæ¥v&£õÀÍ:Pö¨£}Iò½OÿÙ
------------cH2KM7Ij5Ef1ae0cH2ae0KM7ei4Ef1
Content-Disposition: form-data; name="Upload"
Submit Query
------------cH2KM7Ij5Ef1ae0cH2ae0KM7ei4Ef1
Source code...
Code:
main() {
//char *querystring;
int querylen;
char *line;
FILE *fp;
FILE *fp2;
if ( getenv("CONTENT_LENGTH") != NULL ) {
querylen=atoi(getenv("CONTENT_LENGTH"));
line=malloc(querylen*512);
//querystring=malloc(querylen*512);
} else {
querylen=10240;
line=malloc(querylen*512);
//querystring=malloc(querylen*512);
}
char querystring[querylen];
fread ( querystring, querylen, 1, stdin );
printf("Content-type: text/plain\n\n");
fp=fopen("/opt/moneylikes/tmp/file", "wb+");
fwrite(querystring, querylen, 1, fp);
exit(0);
}
I want to say thanks in advanced to anyone who can help me fill in the missing info..
I am pretty sure it is how i handle the headder info with the CGI.. i am just not sure what exactly it is i am doing wrong..