移植cgic至apache实现文件上传

按照网上的说明把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/,再运行文件上传则不会报错;


你可能感兴趣的:(apache,cgi,cgic)