簡體   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