cgi从boa传数据到html,boa cgi + web页实现文件的上传

void File()

{

cgiFilePtr file;

int fd;

mode_t mode;

char name[1024];

char contentType[1024];

char buffer[1024];

int size;

int got;

if (cgiFormFileName("upfile", name, sizeof(name)) != cgiFormSuccess) {

printf("

No file was uploaded.

");

return;

}

fprintf(cgiOut, "The filename submitted was: ");

cgiHtmlEscape(name);

fprintf(cgiOut, "

");

cgiFormFileSize("upfile", &size);

fprintf(cgiOut, "The file size was: %d bytes

", size);

cgiFormFileContentType("upfile", contentType, sizeof(contentType));

fprintf(cgiOut, "The alleged content type of the file was: ");

cgiHtmlEscape(contentType);

fprintf(cgiOut, "

");

fprintf(cgiOut, "Of course, this is only the claim the browser made when uploading the file. Much like the filename, it cannot be trusted.

");

fprintf(cgiOut, "The file's contents are shown here:

");

if (cgiFormFileOpen("upfile", &file) != cgiFormSuccess) {

fprintf(cgiOut, "Could not open the file.

");

return;

}

//打开或创建文件在当前目录,即/var/www/cgi-bin

//注意文件存取权限,否如会出现文件无法访问

mode=S_IRWXU|S_IRGRP|S_IROTH; //

fd = open(name,O_RDWR|O_CREAT|O_TRUNC,mode);

if(fd < 0){

fprintf(cgiOut, "

Could not create the file,error:%d

",fd);

}

fprintf(cgiOut, "");

while (cgiFormFileRead(file, buffer, sizeof(buffer), &got) ==

cgiFormSuccess)

{

//写入文件

if(got>0){

write(fd,buffer,got);

}

cgiHtmlEscapeData(buffer, got);

}

fprintf(cgiOut, "

");

cgiFormFileClose(file);

close(fd);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值