用PHP读取文件名

用PHP读取文件名,php,filesystems,Php,Filesystems,我正在写一个新闻脚本,我很难找到删除文件的方法 如何更改此脚本,使在同一行中具有文件的值 <?php // This function reads all available news function getNewsList(){ $fileList = array(); // Open the actual directory if ($handle = opendir("news")) { //

我正在写一个新闻脚本,我很难找到删除文件的方法

如何更改此脚本,使
在同一行中具有文件的

<?php
    // This function reads all available news
    function getNewsList(){

       $fileList = array();

        // Open the actual directory
        if ($handle = opendir("news")) {
            // Read all file from the actual directory
            while ($file = readdir($handle))  {
                if (!is_dir($file)) {
                    $fileList[] = $file;
            }
            }
        }   

        rsort($fileList);

        return $fileList;
    }

    // new

    $list = getNewsList();
    print("<table>\n");
    print("<tr><td>&nbsp;</td><td>Article Title:</td><td>Post Date:</td></tr>\n");
    foreach ($list as $value) {
        $newsData = file("news/".$value);
        $newsTitle  = $newsData[0];
        $submitDate = $newsData[1]; 
        unset ($newsData['0']);
        unset ($newsData['1']);

        $newsContent = "";
        foreach ($newsData as $value) {
            $newsContent .= $value;
        }

            print("<tr>");
            print("<td><input type=\"checkbox\" name=\"check_files[]\" value=\"$file\" /></td>");
            print("<td>$newsTitle</td>");
            print("<td>");
            print("$submitDate");
            print("</td>");
            print("</tr>\n");

    }  
    print("</table>\n");

没有在任何地方定义
$file
变量,您可以尝试以下操作:

替换

$newsData = file("news/".$value);


$file
变量未在任何地方定义,您可以尝试以下操作:

替换

$newsData = file("news/".$value);


在脚本中,当前文件名似乎存储在
$value
中,因为
$list=getNewsList()
是一个文件名数组,您在上面执行foreach:
foreach($value)列表{

在脚本中,当前文件名似乎存储在
$value
中,因为
$list=getNewsList();
是一个文件名数组,您在上面执行foreach:
foreach($value)列表{

尝试将第二个foreach循环替换为:

foreach ($newsData as $content) {
    $newsContent .= $content;
}
然后使用此行显示文件:


print(“”;
尝试将第二个foreach循环替换为:

foreach ($newsData as $content) {
    $newsContent .= $content;
}
然后使用此行显示文件:


print(“”;

我们看不到脚本顶部定义的函数。我们看不到脚本顶部定义的函数。