链接:https://pan.baidu.com/s/1JH60KeTF3AoAhbb1dMIWnQ
提取码:1111
在http.c中setLocalHost()中将以下代码注释掉
struct hostent *hp;
if ((hp = gethostbyname(host)) == NULL) {
error("Cannot get host address for host %s: errno %d", host, errno);
return -1;
}
memcpy((char*) &intaddr, (char *) hp->h_addr_list[0], (size_t) hp->h_length);
ipaddr = inet_ntoa(intaddr);
在注释代码后加入以下代码
/*struct hostent *hp;
if ((hp = gethostbyname(host)) == NULL) {
error("Cannot get host address for host %s: errno %d", host, errno);
return -1;
}
memcpy((char*) &intaddr, (char *) hp->h_addr_list[0], (size_t) hp->h_length);
ipaddr = inet_ntoa(intaddr);*/
ipaddr="0.0.0.0";
(1) 在upload.c的processUploadHeader函数里 需要将 if (value == ‘.’ || !websValidUriChars(value) || strpbrk(value, "\/:?<>|~"’%`^\n\r\t\f")) {
改为if(*value == ‘.’){
(2) 文件大小限制,goahead-linux-default-me.h里(goahead-linux-default-me.h会替换me.h)ME_GOAHEAD_LIMIT_POST的大小调大,否则上传大文件无法通过。
(3) 临时文件存放路径 #define ME_GOAHEAD_UPLOAD_DIR "tmp"该为#define ME_GOAHEAD_UPLOAD_DIR “/tmp”,上传后的文件会保存在/tmp目录下,路径可以自主调整。
(4) 在upload.c的processContentData函数里吧 wp->currentFile = 0屏蔽,即//wp->currentFile = 0;;
原文链接:https://blog.csdn.net/weixin_40732273/article/details/107831176
本人交叉编译器:arm-linux-gcc
make CC=arm-linux-gcc LD=arm-linux-ld CFLAGS=-fno-stack-protector
拷贝self.key self.crt route.txt auth.txt到开发板
把goahead self.key self.crt route.txt auth.txt 放在开发板同一目录下
把libgo.so放在开发板/lib目录下
在存放goahead的目录下新建一个tmp目录,用于存放上传文件的临时文件夹,例如如图所示
我的www目录存放的是html文件里面有一个cgi-bin目录用于存放cgi程序
./goahaed -v www
在浏览器输入开发板IP地址(需要把网站的第一个页面改名为index.html)即可
led control
远程升级
#include
#include
#include
#define UPLOAD_DIR "/app/goahead/" // 设置文件保存的目录
int main(int argc, char **argv)
{
// 获取请求方法
printf("Content-Type: text/html\n\n");
char *requestMethod = getenv("REQUEST_METHOD");
if (requestMethod == NULL || strcmp(requestMethod, "POST") != 0) {
printf("Status: 405 Method Not Allowed\n\n");
printf("Method Not Allowed");
return 0;
}
// 获取上传的文件数据
char *contentLengthStr = getenv("CONTENT_LENGTH");
printf("contentLengthStr:%s\n\n",contentLengthStr);
if (contentLengthStr == NULL) {
printf("Status: 400 Bad Request\n\n");
printf("Bad Request");
return 0;
}
long contentLength = strtol(contentLengthStr, NULL, 10);//把长度转换为long类型
printf("contentLength:%ld\n\n
",contentLength );
if (contentLength <= 0) {
printf("Status: 400 Bad Request\n\n");
printf("Bad Request");
return 0;
}
char *fileData = malloc(contentLength);
// 获取文件名
// char *filename = getenv("HTTP_X_FILENAME");
char *filename =getenv("FILE_CLIENT_FILENAME_file_path");
printf("file_name=%s\n\n
",filename);
if (filename == NULL) {
printf("Status: 400 Bad Request\n\n
");
printf("Bad Request");
free(fileData);
return 0;
}
//读取临时文件的文件名
char *tmp = getenv("FILE_FILENAME_file_path");
printf("tmp:%s\n\n",tmp);
if (tmp == NULL) {
printf(" the tmp is null\n\n
");
printf("Status: 400 Bad Request\n\n");
printf("Bad Request");
free(fileData);
return 0;
}
char *tempfile[128];
sprintf(tempfile,"/app/goahead/%s",tmp);
printf("tempfile:%s\n\n",tempfile);
// 保存文件到指定目录
char destPath[128];
char cmd[128];
snprintf(destPath, sizeof(destPath), "%s%s", UPLOAD_DIR, filename);
sleep(3);
sprintf(cmd,"cp %s %s",tempfile,destPath);
system(cmd);
FILE *file = fopen(destPath, "r");
if(file == NULL){
printf("the file is null
");
return 0;
}
fseek(file,0,SEEK_END);
int fileSize = ftell(file);
printf("the file size is %d
",fileSize);
fseek(file,0,SEEK_SET);
fread(fileData,1,fileSize,file);
printf("
context:
%s
",fileData);
printf("Content-Type: text/html\n\n");
printf("");
printf("File uploaded successfully!");
printf("");
return 0;
}
网页上传上来的文件在一个临时文件夹里,我的临时文件夹是/app/goahead/tmp/
FILE_FILENAME_file_path环境变量存储了临时文件的路径
只需要用getenv解析 FILE_FILENAME_file_path即可