急需C写的文件上载CGI程序

waitu 2002-11-27 09:04:00
谁能提供sample,感激不尽!!!
我这里有perl写的程序,可是我需要的是C写的,谁有类似程序,请提供信息,十分感谢!!!
...全文
32 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yourway 2002-12-04
  • 打赏
  • 举报
回复
cgic这个模块里面有上载的功能呀!
swcims 2002-12-02
  • 打赏
  • 举报
回复
谢谢yourway(勵磁繞組) ,这个网址上好像没有这个功能哟!
yourway 2002-11-29
  • 打赏
  • 举报
回复
http://www.boutell.com/cgic/
swcims 2002-11-29
  • 打赏
  • 举报
回复
感谢zhukai8144(网络探险者) ,我有一个问题:
由于需要上载一个很大的文件(并且擦写Server上原有的文件),内存不能分配足够大的空间。所以希望能几十K,几十K的读入,边读边更新Server上原有的文件。请问如何解决?谢谢!
zhukai8144 2002-11-29
  • 打赏
  • 举报
回复
表单:
<html>
<body>
<form name=form1 action="http://www.119911.com/cgi-bin/sms-edate/test" method=post enctype="multipart/form-data">
<input type=file name='filename'>
<input type=submit value="提交">
</form>
</body>
</html>

cgi程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char *SAVE_PATH = "file.jpg";//文件存储路径

int main()
{
printf("Content-type:text/html\n\n");

char boundary[128];
sprintf(boundary,strstr(getenv("CONTENT_TYPE"),"boundary")+strlen("boundary")-5);

int n = atoi(getenv("CONTENT_LENGTH")) - strlen(boundary);
char *buff = (char *)malloc(n+1);
fread(buff,1,n,stdin);

FILE *fp;
fp = fopen(SAVE_PATH,"wb+");
char *p = strstr(buff,"\n");
p ++;
p = strstr(p,"\n");
p ++;
p = strstr(p,"\n");
p ++;
p = strstr(p,"\n");
p ++;
int m = p - buff;

fwrite(p,1,(n - m + 1),fp);
fclose(fp);
fflush(stdout);
return 1;
}

应该可以了。第一次编写文件上传,仓促完成,见笑见笑。

2,204

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 CGI
社区管理员
  • CGI社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧