2014-11-15 52 views
0

我正在使用Cgicc構建一個簡單的CGI應用程序。我想在我的網頁中嵌入的圖像,但是,這是一個使用Cgicc嵌入圖像-cgi認爲圖像是腳本

[email protected]:~/www$ python -m CGIHTTPSever 

C++代碼

從CGI

127.0.0.1 - - [15/Nov/2014 13:26:52] code 403, message CGI script is not executable ('/cgi-bin/tmp3.jpg') 

我調用CGI Server實例返回的錯誤

#include <iostream> 
#include <sstream> 
#include <string> 
#include <unistd.h> 
#include <fstream> 
#include <stdlib.h> 
#include "cgicc/Cgicc.h" 
#include "cgicc/HTTPHTMLHeader.h" 
#include "cgicc/CgiDefs.h" 
#include "cgicc/Cgicc.h" 
#include "cgicc/HTTPHTMLHeader.h" 
#include "cgicc/HTMLClasses.h" 
#define cimg_display 0 
#include "CImg.h" 

using namespace std; 
using namespace cgicc; 

int main(int argc, char **argv){ 

try{ 
    Cgicc formData; 
    cout << HTTPHTMLHeader()<<endl; 
    cout << HTMLDoctype(HTMLDoctype::eStrict)<<endl; 
     // Set up the HTML document 
     cout << html() << head() << title("Cgicc example") << head() << endl; 
    cout << body().set("bgcolor","#cccccc").set("text","#000000").set("link","#0000ff").set("vlink","#000080") << endl; 

    cout << img().set("src", "tmp3.jpg").set("height", "100").set("width", "100"); 

    cout << "<form method=\"GET\" action=\"formProcessor.cgi\">"<<endl; 
    cout << h2("Input picure info") <<endl; 
    cout << p("Height")<<endl; 
    cout << "<input type=\"text\" name=\"height\"> <br>"<<endl; 
    cout << p("Width"); 
     cout << "<input type=\"text\" name=\"width\"> <br>"<<endl; 
    cout << "<input type=\"submit\" value=\"Submit\">"<<endl; 
    cout << "</form>"<<endl; 


}catch(exception& e){ 
cout <<"Error"<<endl; 
} 



    return 0; 
} 

有沒有人知道這個問題的解決方案?我一直無法找到關於這個問題的網上很多..

回答

0

原來這裏的問題不是代碼,而是我存儲圖像的目錄。我試圖服從cgi-bin目錄中的圖像,這導致服務器將其解釋爲CGI腳本。我改變了這一行:

cout << img().set("src", "tmp3.jpg").set("height", "100").set("width", "100"); 

這個

cout << img().set("src", "/images/tmp3.jpg").set("height", "100").set("width", "100"); 

並開始正常服務的圖像。該生產線

cout << img().set("src", "tmp3.jpg").set("height", "100").set("width", "100"); 

正在從URL

http://0.0.0.0:8000/cgi-bin/myCGI.cgi 

調用,所以沒有圖像被誤認爲是一個CGI腳本的絕對URL。