Detailed introduction to PHP reading directory function_PHP tutorial

WBOY
Release: 2016-07-15 13:34:38
Original
1249 people have browsed it

What we are here to introduce to you is

  1. < ?php
  2. $base_dir = "filelist/"; > =
  3. opendir($base_dir); echo $base_dir."<
  4. hr/> " ; while($flist=
  5. readdir($fso)){ echo $flist."<
  6. br/>" ; } closedir($fso)
  7. ?>
  8. This means returning the files under the file directory. Directory program (0 files will return false).
  9. Sometimes PHP reading directory function needs to know the directory information. You can use dirname($path) and basename($path) to return the directory part of the path respectively. and the file name part, you can use disk_free_space($path) to return the free space. Creation command:
mkdir($path,0777)

, 0777 is the permission code, it can be set with the umask() function under non-window conditions.

rmdir($path)

will delete files with paths in $path.

dir -- directory class It is also an important class for operating file directories. It has three methods, read, rewind, and close. This is a pseudo-object-oriented class. It first uses a file handle to open the file, and then reads it using a pointer. Here is PHP How the manual describes the PHP read directory function:

Output:

Handle: Resource id #2

Path : /etc/php5

.

..
<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>$</span><span class="attribute">d</span><span> = </span><span class="attribute-value">dir</span><span>("/etc/php5");  </span></li><li class="alt"><span>echo "Handle: " . <br />$d-</span><span class="tag">></span><span>handle . "n";  </span></span></li>
<li>
<span>echo "Path: " . <br>$d-</span><span class="tag">></span><span>path . "n";  </span>
</li>
<li class="alt">
<span>while (false !== <br>($</span><span class="attribute">entry</span><span> = $d-</span><span class="tag">></span><span>read())) {  </span>
</li>
<li><span>echo $entry."n";  </span></li>
<li class="alt"><span>}  </span></li>
<li>
<span>$d-</span><span class="tag">></span><span>close();  </span>
</li>
<li class="alt">
<span class="tag">?></span><span> </span>
</li>
<li><span> </span></li>
</ol>
Copy after login
apache

cgi

cli

The attributes of the file are also very important for the PHP reading directory function. The file attributes include creation time , last modified time, owner, file group, type, size, etc.






http://www.bkjia.com/PHPjc/445977.html

www.bkjia.com

true
http: //www.bkjia.com/PHPjc/445977.html

TechArticleWhat we introduce to you here is?php $ base_dir = filelist/ ; $ fso = opendir ($base_dir) ; echo$base_dir. hr / ; while($ flist = readdir ($fso)){ echo$flist. br / ; } closedir...
source:php.cn
Statement of this Website
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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!