📄 fileupload.c
字号:
// ==================================
// Programmer1: Kaney
// Programmer2: Tai
// ==================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <fcntl.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "cgivars.h"
#include "htmllib.h"
#include <dirent.h>
#include "../sysconf.h"
//want to check file extensions? 1=yes 0=no
//define max size of uploads to 1000M
#define MAXSIZE 2000000000
//define upload directory relative to cgi-bin
// buffer for storing boundary line and file name
#define MAXLINE 512
char szBoundary[MAXLINE];
char szFile[MAXLINE]; //filename to write to char
char myFile[MAXLINE]; //basename of uploaded file
// buffer of arbitrary size for reading from STDIN
#define BUFFSIZE 16*1024 //orig
//#define BUFFSIZE 6*1024 //tai
char szBuff[BUFFSIZE];
int CheckExt(const char *filename)
{
char *p, *q; int len,i,isgood = 0;
//char *goodext[9] = {"gif","jpg","jpeg","png","bmp","tgz","gz","txt"," tar.gz"}; //orig
char *goodext[1] = {"bin"};
char ext[4]; //6 chars plus '\0'
if (!(p = strchr(filename, '.')))
return 0; /*move to first dot */ ++p; /* move past the dot */
if (!(q = strchr(p, '\0')))
return 0; /*move to end of string */
len = q - p;
memcpy(ext, p, len);
ext[len] = '\0';
if(strcmp(ext, goodext[0]) == 0)
{
isgood = 1;
}
/*
for (i=0;i<=9;i++)
{
if(strcmp(ext,goodext[i]) == 0)
{
isgood = 1;
}
}
*/
return isgood;
}
#define FILE_STATUS_UPLOAD_OK 0
#define FILE_STATUS_UPLOAD_FAIL 1
#define FILE_STATUS_EXIST 5
#define FILE_STATUS_TOO_BIG 7
#define FILE_STATUS_NOT_ALLOW 8
#define FILE_STATUS_NO_DATA 11
int getpidbyname(char *p){
FILE *fp ;
char tmpfile[]="/tmp/mypidtest", buffer[100];
char *p_temp = NULL;
char command[100];
memset(command,0,100);
sprintf(command,"ps | grep %s > %s",p,tmpfile);
system(command);
fp = fopen(tmpfile,"r");
if ( fp == NULL ) {
return -1;
}
memset(buffer,0,100);
fgets(buffer,100,fp);
p_temp=strstr(buffer,"/bin/flash_erase"); //To make sure there is a string in tmpfile
fclose(fp);
unlink(tmpfile);
if (p_temp ==NULL) {
return -1;
}
else {
p_temp = strtok(buffer," "); //strtok( )琌ノㄓち秨
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -