Home >Backend Development >PHP Tutorial >PHP code: List files in the current directory_PHP tutorial

PHP code: List files in the current directory_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:56:30764browse

 Agni Website Building Academy (Bkjia.Com) Network Programming There are many ways to list the current file list in PHP on the Internet. Recently, The editor of bkjia.com synthesized some information on the Internet, rewritten it, and felt that this was the best method, so he published the code.

The following is the quoted content:
以下为引用的内容:

function tree($directory)
{
echo date(”Y-m-d H:i:s”);
$i=0;
$mydir=dir($directory);
echo “

    n”;
    while($file=$mydir->read() AND $i<5)
    {
    if((is_dir(”$directory”)) AND ($file!=”.”) AND ($file!=”..”))
    {
    $filetime=date(”Y-m-d H:i:s”,filectime($file));
    //encode spaces
    $file = rawurlencode($file);
    // convert the + (this is one result from the function rawurlencode) in %20
    $url = str_replace(’+’ , ‘%20′ , $file);
    echo “
  • ”.$url.”  $filetime
  • n”;
    $i+=1;
    }
    }
    echo “
n”;
$mydir->close();
}

tree(”.”);  // 列出当前目录
?>

function tree($directory)
{
echo date(”Y-m-d H:i:s”);
$i=0;
$mydir=dir($directory);
echo “
    n”;
    while($file=$mydir->read() AND $i<5)
    {
    if((is_dir(”$directory”)) AND ($file!=”.”) AND ($file!=”..”))
    {
    $filetime =date(”Y-m-d H:i:s”,filectime($file));
    //encode spaces
    $file = rawurlencode($file);
    // convert the + ( this is one result from the function rawurlencode) in %20
    $url = str_replace('+' , '%20′ , $file);
    echo “
  • ”.$url.” $filetime
  • n” ;
    $i+=1;
    }
    }
    echo “
n”;
$mydir->close();
} tree(”.”); // List the current directory
?>

http://www.bkjia.com/PHPjc/364207.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364207.htmlTechArticle
LieHuo.Net Network Programming There are many ways to list the current file list in PHP on the Internet Recently, the editor of liehuo.net synthesized some information on the Internet and rewritten it...
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 admin@php.cn