修改BBSLIB.inc
#define BASEDIR "/tmp/attach/" //save the attach tmp
#define ATTACHDIR "/home/httpd/html/attach/"
增加如下几个函数
int check_attach(char * dir){
DIR * dp;
int i;
struct dirent * entry;
struct stat statbuf;
if((dp=opendir(dir))==NULL){
return;
}
chdir(dir);
i=0;
while((entry=readdir(dp)) != NULL){
stat(entry->d_name,&statbuf);
if(strcmp(".",entry->d_name)==0 || strcmp("..",entry->d_name)==0)
continue;
if(S_ISDIR(statbuf.st_mode))
continue;
i++;
}
chdir(BBSHOME);
closedir(dp);
return i;
}
int copy_file(char * src,char * des){
char buf[1024];
int fd_src,fd_des;
int nread;
fd_src= open(src,O_RDONLY);
if(file_exist(des)) unlink(des);
fd_des= open(des,O_WRONLY | O_CREAT,S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
while((nread=read(fd_src,buf,sizeof(buf)))>0)
write(fd_des,buf,nread);
close(fd_src);
close(fd_des);
}
int mk_attach_dir(char * board){
chdir(ATTACHDIR);
if(file_exist(board)){
if(!file_isdir(board)) unlink(board);
else return;
}
return mkdir(board,S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
}
void show_attach_con(char * dir){
DIR * dp;
int i;
struct dirent * entry;
struct stat statbuf;
if((dp=opendir(dir))==NULL){
return;
}
printf("<table border=0 cellpadding=0 cellspacing=0 width=100%>");
printf("<tr><td colspan=3>附件有:<br>\n");
chdir(dir);
i=1;
while((entry=readdir(dp)) != NULL){
stat(entry->d_name,&statbuf);
if(strcmp(".",entry->d_name)==0 || strcmp("..",entry->d_name)==0)
continue;
if(S_ISDIR(statbuf.st_mode))
continue;
printf("<tr><td><a href='/attach/%s/%s/%s'>附件%d</a>:%20.20s <td>大小:%d字节<td>\n",
getparm("board"), getparm("file"), entry->d_name,
i,entry->d_name,file_size(entry->d_name));
i++;
}
printf("</table>");
chdir(BBSHOME);
closedir(dp);
}
--
FROM www.shuoshuo.net