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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image cgi application

Status
Not open for further replies.

tommybc

Programmer
Joined
Apr 16, 2002
Messages
1
Location
US
I am trying to write a simple c++ cgi application that will open an image (.gif) file and return the contents to the web browser as an image.

example:
<img src=&quot;
So far, I successfully read in an image file using the code below, but when I actually try it out, the web browser (IE) tries to download the executable (and yes, it is in the cgi-bin directory with execute priviledges).

Can anyone tell me what I am doing wrong?

example code:
////////////////////////////////////////////////////
int Image::DisplayImage(char *imgfilename)
{
ifstream inFile;
inFile.open(imgfilename, ios::in | ios::nocreate | ios::binary);
if (inFile.fail())
return 0;

int imgWidth, imgHeight;
imgWidth = 10; //I already know the width
imgHeight = 10; //I already know the height

cout << &quot;Content-type: image/gif\n\n&quot;;
cout << &quot;#define image_width &quot; << imgWidth << &quot;\n&quot;;
cout << &quot;#define image_height &quot; << imgHeight << &quot;\n\n&quot;;

int i, j;
char g;

while (!inFile.eof()) {
inFile.get(g);
cout << hex << (int) g;
}
inFile.close();
cout << &quot;\n&quot;;
return 1;
}
/////////////////////////////////////////////////////
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top