日期:2014-05-16  浏览次数:20440 次

php 遍历文件夹及文件,获取文件名和文件路径存入数据库中
<?php
header("Content-Type:text/html; charset=gbk");
require('../../include/connect.php');    //连接数据库
mysql_query("set names gbk");
 function file_list($path)  
    {  
        if ($handle = opendir($path))//打开路径成功  
        {  
            while (false !== ($file = readdir($handle)))//循环读取目录中的文件名并赋值给$file  
            {  
                if ($file != "." && $file != "..")//排除当前路径和前一路径  
                {  
                    if (is_dir($path."/".$file))  
                    {  
    //                    echo $path.": ".$file."<br>";//去掉此行显示的是所有的非目录文件  
                        file_list($path."/".$file);  
                    }  
                    else  
                    {  
                        echo $path."/".$file."<br>";
$insert_sql = "insert into file values(NULL,'".$file."','".$path."','beizhu',1,0,now(),'shanchuanren','shenheren',now(),'".$path."s/".$file."')";  
//mysql_query($insert_sql);  
                    }  
                }  
            }  
        }  
    }
$path = ".";
file_list($path);
?>