cgi实现网页向服务器传送文件
2016-11-03 17:06
204 查看
linux系统,boa服务器,借助UltraEdit软件。
主要原理就是在缓冲区里定位到RAR压缩文件的头尾,并写入到文件中
代码如下
/*************************a.c***********************/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
using namespace std;
#define MAX_CONTENT_LEN 1024
char szContent[MAX_CONTENT_LEN];
char *p,*q;
int main ()
{
int i,nlen;
cout << "Content-type:text/html\n\r\n";
cout << "<html>\n";
cout << "<head>\n";
cout << "<title>CGI 环境变量</title>\n";
cout << "</head>\n";
cout << "<body>\n";
if ( strcmp("POST", getenv("REQUEST_METHOD")) == 0 )
{
nlen = atoi(getenv("CONTENT_LENGTH"));
for (i = 0; i < nlen; i++ )
{
if ( i < MAX_CONTENT_LEN )
szContent[i] = fgetc(stdin);
else
break;
}
printf("<p>%s</p>", szContent);
for (i = 0; i < nlen; i++ )
printf("%x ", (unsigned char)szContent[i]);
}
p = szContent;
p = (6+4+strstr(p,"stream"));
q = szContent+nlen-46;
int fd = open("2.rar",O_RDWR|O_CREAT,777);
write(fd,p,(int)(q-p));
close(fd);
cout << "</body>\n";
cout << "</html>\n";
return 0;
}
/**************************1.html************************/
<html>
<body>
<form enctype="multipart/form-data"
action="/cgi-bin/a.out"
method="post">
<p>文件:<input type="file" name="userfile" /></p>
<p><input type="submit" value="上传" /></p>
</form>
</body>
</html>
主要原理就是在缓冲区里定位到RAR压缩文件的头尾,并写入到文件中
代码如下
/*************************a.c***********************/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
using namespace std;
#define MAX_CONTENT_LEN 1024
char szContent[MAX_CONTENT_LEN];
char *p,*q;
int main ()
{
int i,nlen;
cout << "Content-type:text/html\n\r\n";
cout << "<html>\n";
cout << "<head>\n";
cout << "<title>CGI 环境变量</title>\n";
cout << "</head>\n";
cout << "<body>\n";
if ( strcmp("POST", getenv("REQUEST_METHOD")) == 0 )
{
nlen = atoi(getenv("CONTENT_LENGTH"));
for (i = 0; i < nlen; i++ )
{
if ( i < MAX_CONTENT_LEN )
szContent[i] = fgetc(stdin);
else
break;
}
printf("<p>%s</p>", szContent);
for (i = 0; i < nlen; i++ )
printf("%x ", (unsigned char)szContent[i]);
}
p = szContent;
p = (6+4+strstr(p,"stream"));
q = szContent+nlen-46;
int fd = open("2.rar",O_RDWR|O_CREAT,777);
write(fd,p,(int)(q-p));
close(fd);
cout << "</body>\n";
cout << "</html>\n";
return 0;
}
/**************************1.html************************/
<html>
<body>
<form enctype="multipart/form-data"
action="/cgi-bin/a.out"
method="post">
<p>文件:<input type="file" name="userfile" /></p>
<p><input type="submit" value="上传" /></p>
</form>
</body>
</html>
相关文章推荐
- 网页嵌入快播播放器并实现服务器视频文件连续播放
- 如何用java实现在网页中保存html编辑器 编辑好的 html 文件?!(如blog里发文章的时候把要发表的内容以html文件的形式保存到服务器上?)
- 使用openfire服务器,在android上实现asmack登陆、状态监视、文本和文件传送。
- 用HttpListener 建立web服务器 实现网页浏览、文件上传
- 网页嵌入快播播放器并实现服务器视频文件连续播放
- 网页嵌入快播播放器并实现服务器视频文件连续播放
- 在MFC下实现POST网页表单,下载服务器文件或取得网页源代码
- php使用curl 实现GET和POST请求(抓取网页,上传文件),支持跨项目和跨服务器
- 简单的SOCKET传送文件和字符串实现
- ASP.NET中实现直接从网页上下载文件
- 如何用C的CGI实现网页的分页显示功能?
- 看这篇文章,不需要别的了----Samba 文件服务器用户复杂权限模型设计和实现
- 用JavaScript与WebService实现网页部分数据XML传送
- PHP实现客户端将CSV文件导入服务器数据库中
- 简单的SOcket传送文件字符串实现
- C#实现从FTP服务器下载压缩文件并解压.
- 实现web服务器的任意文件下载到客户机
- 用JavaScript与WebService实现网页部分数据XML传送
- Webservice传送文件的实现(AXIS2 MTOM)
- Delphi7 中利用Indy的TidFtp客户端控件实现在服务器指定目录下下载需要的文件