http://blog.chinaunix.net/u1/34529/showart_266211.html
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#define ACHEAD "ooooooooooooo"
#define AC483PATH "../htdocs/ac483/ac483_bak"
void fit(char *,unsigned size);
int main(int argc, char *argv[])
{
printf("Content-Type:text/html/n/n");
char *pMethod = getenv("REQUEST_METHOD");
//printf("pMethod=%s/n",pMethod);
if(pMethod == NULL || *pMethod == 0)
{
printf("No Any Method!/n");
return 0;
}
if(strcmp(pMethod, "GET") == 0)
return 1;
if(strcmp(pMethod, "POST") == 0)
{
char *pCntLen = getenv("CONTENT_LENGTH");
//printf("pCntLen=%s/n",pCntLen);
if(!pCntLen)
{
printf("Can't get Content_Length!/n");
return 0;
}
if(*pCntLen == 0)
{
printf("Can't get Content_Length!/n");
return 0;
}
int StrLen = atoi(pCntLen);
// printf("StrLen=%d/n",StrLen);
if(StrLen <= 0)
{
printf("String Length <= 0/n");
return 0;
}
//char *ph = getenv("CONTENT_TYPE");
//printf("ph=%s/n",ph);
char *readstr=(char *)malloc(StrLen+1);
fread(readstr,StrLen,1,stdin);
// printf("readstr=%s/n",readstr);
int n=0;
int firstLineMark=0;
int firstLineCount=0;
int headCount=0;
while(n<4)
{
if(*(readstr++)=='/n')
{
firstLineMark++;
n++;
}
if(firstLineMark==0)
{
firstLineCount++;
}
headCount++;
}
StrLen = StrLen-headCount;
fit(readstr,13);
if(strcmp(readstr,ACHEAD)!=0)
{
printf("<SCRIPT language=JavaScript>alert('文件不正确!');javascript:history.go(-1)</SCRIPT>");
return 0;
}
FILE *fp;
if((fp=fopen(AC483PATH,"wb"))==NULL)
{
printf("error open file/n");
return 0;
}
fwrite(readstr+13,StrLen-13-firstLineCount-5,1,fp);
fclose(fp);
printf("<SCRIPT language=JavaScript>alert('恭喜升级成功!');javascript:history.go(-1)</SCRIPT>");
// printf("恭喜升级成功!");
}
return 0;
}
void fit(char *string,unsigned size)
{
if(strlen(string)>size)
*(string+size)='/0';
}
打开一个文件,上传到服务器指定的文件中.适用于一些软件在线更新.文字
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#define ACHEAD "ooooooooooooo"
#define AC483PATH "../htdocs/ac483/ac483_bak"
void fit(char *,unsigned size);
int main(int argc, char *argv[])
{
printf("Content-Type:text/html/n/n");
char *pMethod = getenv("REQUEST_METHOD");
//printf("pMethod=%s/n",pMethod);
if(pMethod == NULL || *pMethod == 0)
{
printf("No Any Method!/n");
return 0;
}
if(strcmp(pMethod, "GET") == 0)
return 1;
if(strcmp(pMethod, "POST") == 0)
{
char *pCntLen = getenv("CONTENT_LENGTH");
//printf("pCntLen=%s/n",pCntLen);
if(!pCntLen)
{
printf("Can't get Content_Length!/n");
return 0;
}
if(*pCntLen == 0)
{
printf("Can't get Content_Length!/n");
return 0;
}
int StrLen = atoi(pCntLen);
// printf("StrLen=%d/n",StrLen);
if(StrLen <= 0)
{
printf("String Length <= 0/n");
return 0;
}
//char *ph = getenv("CONTENT_TYPE");
//printf("ph=%s/n",ph);
char *readstr=(char *)malloc(StrLen+1);
fread(readstr,StrLen,1,stdin);
// printf("readstr=%s/n",readstr);
int n=0;
int firstLineMark=0;
int firstLineCount=0;
int headCount=0;
while(n<4)
{
if(*(readstr++)=='/n')
{
firstLineMark++;
n++;
}
if(firstLineMark==0)
{
firstLineCount++;
}
headCount++;
}
StrLen = StrLen-headCount;
fit(readstr,13);
if(strcmp(readstr,ACHEAD)!=0)
{
printf("<SCRIPT language=JavaScript>alert('文件不正确!');javascript:history.go(-1)</SCRIPT>");
return 0;
}
FILE *fp;
if((fp=fopen(AC483PATH,"wb"))==NULL)
{
printf("error open file/n");
return 0;
}
fwrite(readstr+13,StrLen-13-firstLineCount-5,1,fp);
fclose(fp);
printf("<SCRIPT language=JavaScript>alert('恭喜升级成功!');javascript:history.go(-1)</SCRIPT>");
// printf("恭喜升级成功!");
}
return 0;
}
void fit(char *string,unsigned size)
{
if(strlen(string)>size)
*(string+size)='/0';
}
打开一个文件,上传到服务器指定的文件中.适用于一些软件在线更新.文字