Home  >  Article  >  Backend Development  >  详细介绍PHP读取目录函数_PHP教程

详细介绍PHP读取目录函数_PHP教程

WBOY
WBOYOriginal
2016-07-15 13:34:381164browse

我们在这里为大家介绍的是

  1.  ?php  
  2. $base_dir = "filelist/";  
  3. $fso = opendir($base_dir);  
  4. echo $base_dir." hr/>" ;  
  5. while($flist=readdir($fso)){  
  6. echo $flist." br/>" ;  
  7. }  
  8. closedir($fso)  
  9. ?> 
  10.  

这是讲返回文件目录下面的文件已经目录的程序(0文件将返回false).

有时候PHP读取目录函数需要知道目录的信息,可以使用dirname($path)和basename($path),分别返回路径的目录部分和文件名名称部分,可用disk_free_space($path)返回看空间空余空间.

创建命令:

mkdir($path,0777)

,0777是权限码,在非window下可用umask()函数设置.

rmdir($path)

将删除路径在$path的文件.

dir -- directory 类也是操作文件目录的重要类,有3个方法,read,rewind,close,这是一个仿面向对象的类,它先使用的是打开文件句柄,然后用指针的方式读取的.,这里看php手册是怎么描述PHP读取目录函数的:

  1.  ?php  
  2. $d = dir("/etc/php5");  
  3. echo "Handle: " . 
    $d-
    >handle . "n";  
  4. echo "Path: " . 
    $d-
    >path . "n";  
  5. while (false !== 
    ($
    entry = $d->read())) {  
  6. echo $entry."n";  
  7. }  
  8. $d->close();  
  9. ?> 
  10.  

输出:

Handle: Resource id #2
Path: /etc/php5
.
..
apache
cgi
cli

文件的属性对于PHP读取目录函数也非常重要,文件属性包括创建时间,最后修改时间,所有者,文件组,类型,大小等.


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445977.htmlTechArticle我们在这里为大家介绍的是 ?php $ base_dir = filelist/ ; $ fso = opendir ($base_dir); echo$base_dir. hr / ; while($ flist = readdir ($fso)){ echo$flist. br / ; } closedir...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]