使用RecursiveDirectoryIterator时找不到文件

时间:2012-03-24 20:18:01

标签: php directory

我正在使用以下内容尝试列出customers目录中的所有文件。它应该使用GET中保存的上一页中的客户ID替换路径中的$ customerID,但我收到错误消息:

  

500 -   RecursiveDirectoryIterator :: __ construct(./ customer-files / $ customerID,。/ customer-files / $ customerID)[recursivedirectoryiterator .-- construct]:系统找不到   文件指定。 (代码:2)

<?php
$customerID = $_GET['customerID'];
echo '<h1>';
echo $customerID;
echo '</h1>';
?>


<?php
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('./customer-files/$customerID')) as $filename)
{
    echo '<p>';
    echo $filename->getFilename();

    echo '</p>';
}
?>  

1 个答案:

答案 0 :(得分:1)

您在$ customerID变量周围使用单引号,因此您必须连接或将其切换为双引号,请尝试以下操作:

foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator('./customer-files/' . $customerID)) as $filename)