Home > Backend Development > PHP Tutorial > visitseoul php visitFile traverses the specified folder function

visitseoul php visitFile traverses the specified folder function

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 08:43:38
Original
1138 people have browsed it

Note: visitFile() has a few modifications

Copy the code The code is as follows:


// View the files in the specified folder
$fileList = array();
function visitFile($path)
{
global $fileList;
$path = str_replace("\", "/", $path);
$fdir = dir($path);
while (($file = $fdir->read()) !== false)
{
if($file == '.' || $file == '..'){ continue; }
$pathSub = preg_replace("*/{2,}*", "/ ", $path."/".$file); // Replace multiple backslashes
$fileList[] = is_dir($pathSub) ? $pathSub."/" : $pathSub;
if(is_dir($pathSub )){ visitFile($pathSub); }
}
$fdir->close();
return $fileList;
}
?>


$path = str_replace("\", "/", $path);
$path = preg_replace("*/{2,}*", " /", $path);
?>
Path:

< ;li>Disk root directory/
  • Network local./phpMyAdmin

  • Local disk file://C: or C:

  • < br>



    if(!empty($path)){
    $path = preg_replace("*/{2,}*", "/", $path);
    $files = visitFile($path) ;
    switch(strtolower($_GET["action"]))
    {
    case "view":
    foreach($files as $key => $value)
    {
    printf("No.%4d·%s< ;br>rn", $key+1, $value);
    }
    break;
    case "delete":
    $faileFiles = array();
    foreach(array_reverse($files) as $value)
    {
    if (!unlink($value))
    {
    array_push($faileFiles, $value);
    }
    }
    if(!unlink($path)) { array_push($faileFiles, $path); }
    if(count( $faileFiles) > 0)
    {
    printf("

    Deletion failed file (%d):

    rn", count($faileFiles));
    foreach( $faileFiles as $ key => $value)
    {
    printf("No.%4d·%s
    rn", $key+1, $value);
    }
    }
    break;
    }
    }
    ?>

    The above introduces the visititseoul php visitFile function to traverse the specified folder, including the content of visitseoul. I hope it will be helpful to friends who are interested in PHP tutorials.

    Related labels:
    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