cgi 上传文件(c 语言) 进度条显示

本文介绍了如何用C语言编写CGI程序来实现文件上传,并结合隐藏iframe展示上传进度条。通过编译代码`gcc -o upload upload.c`,可以实现大文件上传且效果良好,支持数百兆文件的无压力上传。
摘要由CSDN通过智能技术生成
//虚拟机上搭建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
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值