background image

                    

}  

                    

else

  

                    

{  

                        echo

 

$file

;  

                    

}  

               

}  

           

}  

        

}  

        closedir

(

$handle

);  

    

}  

 
因为自己要提供路径选择的功能,最好是有一个下拉菜单,里面有待选路径的显示,这样
方便很多,于是自己改了改,把路径输出成一个无序列表。
下面是一个取得当前文件下所有子文件路径的代码:
代码如下

:

 

/*获取指定目录文件路径列表

 

*$path 指定的目录,默认为当前目录

 

*$ifchild 是否获取子目录文件列表,默认不获取

 

*$curpath 显示当前的路径,默认为从当前目录开始

 

*&$pach_html_srt 传递一个外部变量的引用进来,因为此方法有可能被递归调用,所以以

这样的方式来保存

 

*      一些信息,也可以用全局变量来实现,在函数内部变量改变也影响到外部。

 

*&$path_ref_count 原理同上,一个计数标志,如果递归,计数器从上一次保存的值开始自

 

*/

function

 openpath(

$path

=".",

$ifchild

=false,&

$path_html_str

,&

$path_ref_count

)

    

$handle

 = opendir(

$path

);

 

if

(

$handle

)

 

    

while

(false !== (

$file

 = readdir(

$handle

)))

    

{

     

if

 (

$file

 != "." && 

$file

 != "..") 

     

{

    

$fullPath

 = 

$path

.DIRECTORY_SEPARATOR.

$file

;

    

if

(

is_dir

(

$fullPath

))

//如果文件是目录

    

{

     

$path_html_str

.='<li rel="'.

$path_ref_count

++.'">';

     

$path_html_str

.=

$file

.'<ul>';

      

if

(

$ifchild

)

      

{

      

//递归

      

openpath(

$path

.DIRECTORY_SEPARATOR.

$file

,