Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C cgi jpeg transmission howto 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
could someone show me a example of how to send a jpeg format picture through apache? I have searched all over the web but I can't seem to find any examples of this. I've tried a few different things but none of them seem to work :( Thanks.
 
I just want a counter program to run when people access index.html. I have decided to get this to run by adding an img src=pic.cgi tag. That way I can get it to run when people go to my site. I am using Apache on slackware linux. All I want it to do is display a pic on index.html, but I could not find any information on how to do that on the internet. I know you need printf("Content-type: image/jpeg\n\n"); but I do not know what is suppost to come after that to get it to send, and display on the page.... That is what I was asking. Does this make sense??
 
First you have to print HTTP response header (the last line is followed by two newline characters), which you seem to know.

To write the image, In C, you could just open the image file for reading in binary mode and then write each byte read to stdout. Here's a rough idea:

#include <stdio.h>

/* ... */

int main(void)
{
FILE *fp
unsigned char buf[1];

/* Write HTTP response header */

fp=fopen(&quot;whatever.jpg&quot;,&quot;rb&quot;);
if (fp!=NULL) {
while (fread(&buf,1,1,fp)) {
fwrite(&buf,1,1,stdout);
}
fclose(fp);
}
return 0;
}

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top