//虚拟机上搭建apache服务器上传文件
//1.代码:
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include "dirent.h"
#include <wchar.h>
#include <assert.h>
static int atoii (char *zzzz)
{
int i = 0;
int num=0;
for(i=0;i<20;i++)
{
if(zzzz[i] >= '0' && zzzz[i] <= '9')
{
num = num * 10 + (zzzz[i] - '0');
}else
{
break;
}
}
return num;
}
char* getCgiData(FILE* fp, char* requestmethod)
{
char* input;
int len;
char *pppp;
int size = 1024;
int i = 0;
if(!strcmp(requestmethod, "GET"))
{
input = getenv("QUERY_STRING");
return input;
}
else if (!strcmp(requestmethod, "POST"))
{
pppp=getenv("CONTENT_LENGTH");
len = atoii(pppp);
input = (char*)malloc(sizeof(char)*(size + 1));
if (len == 0)
{
input[0] = '\0';
return input;
}
fgets(input, len+1, stdin);
input[len]='\0';
return input;
}
return NULL;
}
static unsigned int tmppp=0;
char *getFileName(unsigned char *req)
{
int i;
int leng;
tmppp=0;
char *psz1; char *psz2;
unsigned char *cur_post,*buf;
// get filename keyword
if ((psz1=strstr(req, "filename=")) == NULL)
{
return (char *)&tmppp;
}
// get pointer to actual filename (it's in quotes)
psz1+=strlen("filename=");
if ((psz1 = strtok(psz1, "\"")) == NULL)
{
return (char *)&tmppp;
}
// remove leading path for both PC and UNIX systems
if ((psz2 = strrchr(psz1,'\\')) != NULL)
{
psz1 = psz2+1;
}
if ((psz2 = strrchr(psz1,'/')) != NULL)
{
psz1 = psz2+1;
}
return psz1;
}
main()
{
char *reqMethod;
char *wp;
char *var=NULL;
int len;
long total,i,count;
char *fileName,*ps1,*ps2;
char *fileN;
char Boundary[256];
char errorBuf[200]="";
char tmpBuf[512];
char filePath[256]="/usr/local/apache2/webdav/";//directory of uploaded file
FILE *fileBuf=NULL;
reqMethod=getenv("REQUEST_METHOD");
len=atoii(getenv("CONTENT_LENGTH"));
printf("%s","Content-type:text/html \r\n\r\n");
//printf("<h
cgi 上传文件(c 语言) 进度条显示
最新推荐文章于 2024-07-05 15:59:18 发布
本文介绍了如何用C语言编写CGI程序来实现文件上传,并结合隐藏iframe展示上传进度条。通过编译代码`gcc -o upload upload.c`,可以实现大文件上传且效果良好,支持数百兆文件的无压力上传。
摘要由CSDN通过智能技术生成