web是这样写的:
<html>
<head>
<title>Test</title>
</head>
<body>
<form action="cgi-bin/PostTest.cgi" method="POST">
<input type="file" name="file" value="" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
我想点击Submit之后PostTest.cgi 可以接受到上传的文件,
不知道用c 怎么处理。可以使用libcgi这个库。
我的代码是这样的:可是无法实现。
- C/C++ code
#include <stdio.h> #include "cgi.h" int main() { cgi_init(); cgi_process_form(); cgi_init_headers(); puts("" "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>" "<html>" "<head>" " " " <meta http-equiv='content-type' content='text/html; charset=ISO-8859-1'>" " " " <meta name='author' content='Rafael Steil'>" " <title>LIBCGI Examples</title>" " </head>" " <body text='#000000' bgcolor='#ffffff' link='#0000ee' vlink='#551a8b' alink='#0000ee'>" ""); if (cgi_param("name")) { printf("name: %s<br>", cgi_param("name")); } else { puts("name: Empty<br>"); } if (cgi_param("number")) { printf("number: %s<br>", cgi_param("number")); } else { puts("number: Empty<br>"); } //char **lines; //unsigned int total, i; // printf("Content-Type: application/xml\n\n"); printf("Content-Disposition: attachment; filename=DOWNLOAD.xml\n\n"); printf("file name = : %s<br>", cgi_param("file")); FILE *fp = fopen(cgi_param("file"), "rb"); if(fp != NULL) { printf("Open file [%s] Successfully<br>", cgi_param("file")); } else { printf("Open file [%s] Erroy<br>", cgi_param("file")); } puts("" "</body>" "</html>" ""); cgi_end(); return 0; }
------解决方案--------------------
cgi.h 和 cgi.cpp 文件能给我看看吗》?
------解决方案--------------------
cgi程序如果在vs6.0里面的话,服务器用apache运行cgi程序需要配置哪些东西呀?