删除列表中的文件.看到新线



我在删除文件中列出的文件时遇到问题。每行一个文件名

在任何时候都不会有超过10个左右的列表。似乎也将读取到unlink命令中,并显示错误,没有这样的文件名。

我试过推荐的rtrim,运气不太好。

文件名

file1.php
file2.php
file3.php
file4.php
etc...

这是我尝试使用的代码。

if(file_exists($filename)) {
$handle = fopen("$filename", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
    // process the line and delete read file.
        unlink("$line");
    }
}
else
    {
        // error opening the file.
    }
    fclose($handle);
while (($line = fgets($handle)) !== false) {
    // process the line and delete read file.
    $line = trim($line);
    if (strlen($line) && file_exists($line)) {
        unlink($line);
    }
}

最新更新