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="
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:isplayImage(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 << "Content-type: image/gif\n\n";
cout << "#define image_width " << imgWidth << "\n";
cout << "#define image_height " << imgHeight << "\n\n";
int i, j;
char g;
while (!inFile.eof()) {
inFile.get(g);
cout << hex << (int) g;
}
inFile.close();
cout << "\n";
return 1;
}
/////////////////////////////////////////////////////
example:
<img src="
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:isplayImage(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 << "Content-type: image/gif\n\n";
cout << "#define image_width " << imgWidth << "\n";
cout << "#define image_height " << imgHeight << "\n\n";
int i, j;
char g;
while (!inFile.eof()) {
inFile.get(g);
cout << hex << (int) g;
}
inFile.close();
cout << "\n";
return 1;
}
/////////////////////////////////////////////////////