移植cgic至apache实现文件上传

将cgic库移植到Apache的cgi-bin目录后,尝试通过'File Upload'功能上传文件时遇到'Internal Server Error'。错误原因是服务器权限设置不当。通过执行`chmod -R 333 /tmp/`命令更改/tmp/目录权限,成功解决了这个问题,允许文件上传操作正常进行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

按照网上的说明把cgic中的“capture”和“cgictest.cgi”移植到开发板上的apache的cgi-bin目录下,但是在网页上运行“File Upload”按钮上传文件时,始终出现错误:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, lianxj@LINUXSERVER and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


Apache/1.3.41 Server at 192.192.192.200:80 Port 80

查看error_log,错误为:Premature end of script headers,这是cgic库main函数中判断是文件上传即存在"multipart/form-data"时,调用函数cgiParsePostMultipartInput()时出错,具体是cgiParsePostMultipartInput()中调用函数getTempFileName(tfileName)时出错,再具体是getTempFileName(tfileName)里面执行如下语句时出错:

int outfd; 
strcpy(tfileName, cgicTempDir "/cgicXXXXXX");
outfd = mkstemp(tfileName);                             //出错
if (outfd == -1) {
return cgiParseIO;
}
close(outfd);

出错原因:cgicTempDir 定义为“/tmp”,但是“/tmp”文件夹的权限不够;

解决方法:输入命令:chmod -R 333 /tmp/,再运行文件上传则不会报错;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值