如何使用c语言编写的cgi程序上传图像文件?

时间:2022-04-15 23:08:59

I wanted to upload a jpeg image file on the server.I have a GoAhead web server which supports only cgi c program as a serverside handeling.

我想在服务器上上传一个jpeg图像文件。我有一个GoAhead Web服务器,它只支持cgi c程序作为服务器端的handeling。

Can any one know how to handle http posted image file in program witten in cgi in c language?

任何人都可以知道如何在c语言的cgi程序中处理http发布的图像文件?

2 个解决方案

#1


0  

To get POST data just read stdin. Environment variable CONTENT_LENGTH tells you how much to expect but of course you need to make your code robust against whatever a potentially malicious user can throw at you.

要获取POST数据,只需读取stdin即可。环境变量CONTENT_LENGTH告诉您预期多少,但当然您需要使代码能够针对潜在恶意用户可能引发的任何攻击。

#2


0  

The GoAhead web server has a file upload filter for this purpose. The upload filter receives the uploaded file and saves it to disk. It then sets some request variables describing the upload. Those variables are accessible via CGI or via action functions or JST templates.

GoAhead Web服务器具有用于此目的的文件上载过滤器。上传过滤器接收上传的文件并将其保存到磁盘。然后设置一些描述上传的请求变量。这些变量可通过CGI或动作函数或JST模板访问。

There is an example in test.c. Search for uploadTest().

test.c中有一个例子。搜索uploadTest()。

See: https://github.com/embedthis/goahead/blob/master/test/test.c

#1


0  

To get POST data just read stdin. Environment variable CONTENT_LENGTH tells you how much to expect but of course you need to make your code robust against whatever a potentially malicious user can throw at you.

要获取POST数据,只需读取stdin即可。环境变量CONTENT_LENGTH告诉您预期多少,但当然您需要使代码能够针对潜在恶意用户可能引发的任何攻击。

#2


0  

The GoAhead web server has a file upload filter for this purpose. The upload filter receives the uploaded file and saves it to disk. It then sets some request variables describing the upload. Those variables are accessible via CGI or via action functions or JST templates.

GoAhead Web服务器具有用于此目的的文件上载过滤器。上传过滤器接收上传的文件并将其保存到磁盘。然后设置一些描述上传的请求变量。这些变量可通过CGI或动作函数或JST模板访问。

There is an example in test.c. Search for uploadTest().

test.c中有一个例子。搜索uploadTest()。

See: https://github.com/embedthis/goahead/blob/master/test/test.c