RecursiveIteratorIterator工作怎么样?
PHP手册没有任何记录或解释.IteratorIterator和之间有什么区别RecursiveIteratorIterator?
我需要在子目录中的所有文件中创建一个循环.你可以帮我构建我的代码,如下所示:
$main = "MainDirectory";
loop through sub-directories {
loop through filels in each sub-directory {
do something with each file
}
};
Run Code Online (Sandbox Code Playgroud)
你能帮忙吗,PLZ?
我已经看到了列出目录中所有文件的函数但是如何列出子目录中的所有文件,所以它返回一个像?
$files = files("foldername");
Run Code Online (Sandbox Code Playgroud)
所以$files 是类似的东西
array("file.jpg", "blah.word", "name.fileext")
Run Code Online (Sandbox Code Playgroud) 我一直试图找出一种方法来列出目录中包含的所有文件.我不太适合使用php自己解决它,所以希望有人可以帮助我.
我需要一个简单的PHP脚本,它将我的images目录中包含的所有文件名加载到一个数组中.任何帮助将不胜感激,谢谢!
我有这个函数返回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) 如何使用SPL,可能使用RecursiveDirectoryIterator和检索完整目录树RecursiveIteratorIterator?
我有一个php脚本,它读取一个目录,并以链接形式列出所有文件/目录,它可以工作,除了我试图让它递归,这样当我选择另一个目录时,它再次使用脚本来显示里面的文件.现在,当我选择一个目录时,它只是转到默认的apache列表....任何帮助表示赞赏.
脚本:
<?php
$dirname = '/drives/Storage/AppsOSs/';
$webdirname = '/AppsOSs'; // what the directory appears as from the web browser's point of view
$dir = opendir($dirname);
$file_list = '';
while(($file = readdir($dir)) != false) {
if(($file != '.') && ($file != '..')) {
$file_list .= "<a href=\"$webdirname/$file\">$file</a><br/>";
}
}
closedir($dir);
?>
<p>
<?=$file_list?>
</p>
Run Code Online (Sandbox Code Playgroud) 我试图得到一个文件夹和子文件夹的列表,我有以下,允许我获取文件夹和子文件夹,但我需要它像以下我一直在尝试,但我不知道我会得到如何整理周围.
Root/
Root/Images
Root/Images/UserImages
Root/Text/
Root/Text/User1/
Root/Text/User1/Folder2
Run Code Online (Sandbox Code Playgroud)
但在这个方面它的显示是这样的
Root/css/
tree/css/
js/
images/
Run Code Online (Sandbox Code Playgroud)
PHP代码:
function ListFolder($path)
{
$dir_handle = @opendir($path) or die("Unable to open $path");
//Leave only the lastest folder name
$dirname = end(explode("/", $path));
//display the target folder.
echo ("$dirname/");
while (false !== ($file = readdir($dir_handle)))
{
if($file!="." && $file!="..")
{
if (is_dir($path."/".$file))
{
//Display a list of sub folders.
ListFolder($path."/".$file);
echo "<br>";
}
}
}
//closing the directory
closedir($dir_handle);
}
ListFolder("../");
Run Code Online (Sandbox Code Playgroud)
谢谢