菜鸟求助,在线等 先说下偶的需求,我在做一个实验报告提交系统,现在需要统计文件夹sy中每个学生提交的实验报告(doc文档)的份数并显示在网页上,要怎么做呢。大牛们帮帮忙,急用呀 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用遍历函数把sy文件夹遍历一遍就可以统计份数了,同时可以获取文件名并显示,具体可以看看php手册查查关于文件的操作那部分,例子比较详细,实例化。 展示可以这样写foreach (glob("sy/*.doc") as $filename) { echo $filename . "\n";}下载的话可以搜索一下相关代码 自己去查php函数,遍历文件夹的文件,计数,获取文件后缀名,或者像楼上说的用正则匹配文件名 <?php$count=0;header("content-type:text/html;charset=gb2312");$file_path = $_SERVER['DOCUMENT_ROOT']."/sy";find_files($file_path);echo "文件份数".$count;function find_files($file_path){ if(is_dir($file_path)){ if ($dh = opendir($file_path)) { while (($file_name = readdir($dh)) !== false) { if($file_name!="."&&$file_name!=".."){ if(filetype($file_path.$file_name)!="dir"){ $count+=1; echo "filename:$file_path.$file_name"; }else{ find_files($file_path.$file_name."/"); } } } closedir($dh); } } }?> 那你的doc文件是如何分步的?每个学生一个文件夹还是?最好截个图出来。 PHP 做计算题 joomla优秀扩展汉化分享 向高手求正则 表达式 网站伪静态化本地测试成功,在服务器上就不行 更多免费资源 phpwind建站的首页下拉菜单导航怎么做的 有没有只能缩略图的类啊 thinkphp3.1缓存失败 phpcms官方默认模板中的一个怪事 [复制链接] 最近新做了个网站,在阿里云sts检查出了BUG,请问如何解决 PHP 如何用正则表达式替换链接 ecshop中can't parse to JSON这个错误怎么解决
foreach (glob("sy/*.doc") as $filename) {
echo $filename . "\n";
}
下载的话可以搜索一下相关代码
$count=0;
header("content-type:text/html;charset=gb2312");
$file_path = $_SERVER['DOCUMENT_ROOT']."/sy";
find_files($file_path);
echo "文件份数".$count;
function find_files($file_path){
if(is_dir($file_path)){
if ($dh = opendir($file_path)) {
while (($file_name = readdir($dh)) !== false) {
if($file_name!="."&&$file_name!=".."){
if(filetype($file_path.$file_name)!="dir"){
$count+=1;
echo "filename:$file_path.$file_name";
}else{
find_files($file_path.$file_name."/");
}
}
}
closedir($dh);
}
}
}
?>