相关疑难解决方法(0)

PHP获取给定目录的所有子目录

如何在没有文件.(当前目录)或..(父目录)的情况下获取给定目录的所有子目录,然后使用函数中的每个目录?

php get list subdirectory

130
推荐指数
6
解决办法
19万
查看次数

PHP递归目录路径

我有这个函数返回full directory tree:

function getDirectory( $path = '.', $level = 0 ){

$ignore = array( 'cgi-bin', '.', '..' );
// Directories to ignore when listing output. Many hosts
// will deny PHP access to the cgi-bin.

$dh = @opendir( $path );
// Open the directory to the handle $dh

while( false !== ( $file = readdir( $dh ) ) ){
// Loop through the directory

    if( !in_array( $file, $ignore ) ){
    // Check that this file is not …
Run Code Online (Sandbox Code Playgroud)

php directory recursion path

8
推荐指数
1
解决办法
1万
查看次数

如何获取子文件夹的文件列表并使用 php 将它们写入 JSON?

我已经能够列出所有文件名和当前目录/文件夹,但我不知道如何为子目录创建 JSON 条目

这是我的代码

<?php
$dir = "office/";
if(is_dir($dir)){
    if($dh = opendir($dir)){
        while(($file = readdir($dh)) != false){
            if($file != "." and $file != ".."){
                $files_array[] = array('file' => $file); // Add the file to the array
            } 
        }
    }
    $return_array =array('dir' => $files_array);
    exit (json_encode($return_array));
}
?>
Run Code Online (Sandbox Code Playgroud)

和输出是

{
    "dir": [
        {
            "file": "FreeWallpapersApp.zip"
        },
        {
            "file": "20151211_ClipArtForTextView.7z"
        },
        {
            "file": "QRite.7z"
        },
        {
            "file": "CustomDialog_app_contacts.zip"
        },
        {
            "file": "LockScreenBasicApp.apk"
        },
        {
            "file": "ImgViewEffects.zip"
        },
      ]
    }
Run Code Online (Sandbox Code Playgroud)

如何使用 php 显示子文件夹中的文件以生成子目录中的文件名。

php json

3
推荐指数
1
解决办法
4957
查看次数

标签 统计

php ×3

directory ×1

get ×1

json ×1

list ×1

path ×1

recursion ×1

subdirectory ×1