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这个库。
我的代码是这样的:可是无法实现。
#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"));