dqa35710 2012-05-02 16:21 采纳率: 0%
浏览 33

获取系统文件夹外部目录中所有文件的列表

i am new to yii and i need to get a list of files inside a directory outside of the system folder. i tried it with

        $fileListOfDirectory = array();
        $pathTofileListDirectory = Yii::app()->request->baseUrl.'/path/to/files';
        foreach( new DirectoryIterator($pathTofileListDirectory) as $file) {
            if( $file->isFile() === TRUE && $file->getBasename() !== '.DS_Store' && substr(strrchr($file->getPathname(), '.'), 1) == 'txt') {
                array_push($fileListOfDirectory, $file->getBasename());
            }
        }

but I allways get the error

DirectoryIterator::__construct(/myYiiInstallation/system/path/to/files) [directoryiterator.--construct]: failed to open dir: No such file or directory

from the line

foreach( new DirectoryIterator($pathTofileListDirectory) as $file) {

So is there another way to get the list of files or what should I do? thnx!

  • 写回答

2条回答 默认 最新

  • douli2063 2012-05-02 16:47
    关注

    You can use this ....

    $fileListOfDirectory = array ();
    $pathTofileListDirectory = Yii::app()->request->baseUrl.'/path/to/files' ;
    
    if(!is_dir($pathTofileListDirectory ))
    {
        die(" Invalid Directory");
    }
    
    if(!is_readable($pathTofileListDirectory ))
    {
        die("You don't have permission to read Directory");
    }
    
    foreach ( new DirectoryIterator ( $pathTofileListDirectory ) as $file ) {
        if ($file->isFile () === TRUE && $file->getBasename () !== '.DS_Store') {
    
            if ($file->getExtension () == "txt") {
                array_push ( $fileListOfDirectory, $file->getBasename () );
            }
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析