TINYHTTPD is a very good tool to learn the HTTP protocol, but because it is too simple to display pictures on the Web page, so I changed some code, so that TINYHTTPD can be realistic images for beginners to learn and familiar with the HTTP protocol, ubuntu14.04 under direct make can, has been tested pass.
Code: download.csdn.net/detail/qiankun1993/9524289
The main increase is two functions, the first is the function of the image wrapper header, when transferring the picture, the Content-type in the HTML header is set to Image/png:
void Headers2 (int client,Constchar *FileName) {Char buf[1024]; (void) filename;/*Could use filename to determine file type*/strcpy (BUF, "http/1.0 ok\r\n); Send (client, buf, strlen (BUF), 00 "content-type:image/png\r\n" ); Send (client, buf, strlen (BUF), 0 "\r\n" ); Send (client, buf, strlen (BUF), 0
The second is a function to read the local picture file, using the following CAT2 () to read the image file's data:
void Cat2 (int client, FILE *resource) {char buf[1024char C; while ((fscanf (Resource, " %ceof) { Send (client, &c, 1, 0 ); printf ( "%c" ,C); } printf ( "%c" ,C)}
Then you can display the image on the Web page, this is only for beginners to learn, Daniel do not despise me.
Upgrade tinyhttpd-0.1.0 to support Web page display images