1 Star 0 Fork 0

Towel Roll/boa+cgi+sh+updatedeb

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
upload.c 1.77 KB
一键复制 编辑 原始数据 按行查看 历史
embedfire 提交于 2022-01-12 10:10 +08:00 . 2022.1.12
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/stat.h>
#include"cgic.h"
#define BufferLen 1024
int cgiMain(void){
cgiHeaderContentType("text/html");
cgiFilePtr file;
char name[1024];
char contentType[1024];
char buffer[1024];
int size;
int got;
if (cgiFormFileName("file", name, sizeof(name)) != cgiFormSuccess) {
printf("<p>No file was uploaded.<p>\n");
return 0;
}
fprintf(cgiOut, "The filename submitted was: ");
cgiHtmlEscape(name);
fprintf(cgiOut, "<p>\n");
cgiFormFileSize("file", &size);
fprintf(cgiOut, "The file size was: %d bytes<p>\n", size);
cgiFormFileContentType("file", contentType, sizeof(contentType));
fprintf(cgiOut, "The alleged content type of the file was: ");
cgiHtmlEscape(contentType);
fprintf(cgiOut, "<p>\n");
fprintf(cgiOut, "Of course, this is only the claim the browser made when uploading the file. Much like the filename, it cannot be trusted.<p>\n");
fprintf(cgiOut, "The file's contents are shown here:<p>\n");
if (cgiFormFileOpen("file", &file) != cgiFormSuccess) {
fprintf(cgiOut, "Could not open the file.<p>\n");
return 0;
}
//打开或创建文件在当前目录,即/var/www/cgi-bin
//注意文件存取权限,否如会出现文件无法访问
mode_t mode=S_IRWXU|S_IRGRP|S_IROTH; //
int fd = open(name,O_RDWR|O_CREAT|O_TRUNC,mode);
if(fd < 0){
fprintf(cgiOut, "<p>Could not create the file,error:%d<p>\n",fd);
}
fprintf(cgiOut, "<pre>\n");
while (cgiFormFileRead(file, buffer, sizeof(buffer), &got) ==
cgiFormSuccess)
{
//写入文件
if(got>0){
write(fd,buffer,got);
}
// cgiHtmlEscapeData(buffer, got);
}
fprintf(cgiOut, "</pre>\n");
cgiFormFileClose(file);
close(fd);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/towel-roll/boa-cgi-sh-updatedeb.git
git@gitee.com:towel-roll/boa-cgi-sh-updatedeb.git
towel-roll
boa-cgi-sh-updatedeb
boa+cgi+sh+updatedeb
master

搜索帮助