繁体   English   中英

在php中链接目录和文件

[英]linking directories and files in php

您好stackoverflow社区;

我正在尝试使用php在目录中显示一些文件,并且显示出来:

在我的文件(“沙拉”)中,我有三个配方文件(“ recipe1.txt”,recipe2.txt,“ recipe3.txt”),我想显示它们,因此我在编写以下内容:

        $script = opendir('salad');
          while(false !==($file = readdir($script))) {
             if (is_file($file)) {
               echo "<p>$file</p>";
                 }
             }

不幸的是,这仅回显到屏幕.DS_store,我在做什么错?

您可以使用此:

<?php
$dir = "/tmp"; // put what suits you here
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
}

sort($files);

print_r($files);

rsort($files);

echo"$files";

?>

来源: http : //php.net/manual/en/function.scandir.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM