php 访问目录,文件

 

$rootDir = './lib/Controller/Topic';
$dirScan = scandir($rootDir);

$urls = array();
$c = 'Topic_';
foreach ($dirScan as $secDir) {
    if (in_array($secDir, array('.', '..', '.svn'))) {
        continue;
    }

    $dir = $rootDir . '/' . $secDir;
    $fdir = opendir($dir);
    while ($path = readdir($fdir)) {
        if (in_array($path, array('.', '..', '.svn'))) {
            continue;
        }
        $filename = $dir . '/' . $path;
//        if (is_dir($secdDir)) {exit('here');
//            $secfdir = opendir($secdDir);
//            while ($path2 = readdir($fdir)) {
//                if (in_array($path2, array('.', '..', '.svn'))) {
//                    continue;
//                }
//                if (is_dir($secdDir . '/' . $path2)) {
//                    exit('dir');
//                } else {
//                    $control = 'Topic_' . $secDir . '_' . $path . '_' . substr($path2, 0, strpos($path2, '.'));
//                }
//            }
//        } else {
        $content = file_get_contents($filename);
        $isMatch = preg_match_all('#\$this->tpl = \'(.*)\'#', $content, $matches);
        if(!$isMatch) {
            echo $filename;
            echo PHP_EOL;
            continue;
//            exit('not match tempate');
        }
        
        
            $control = 'Topic_' . $secDir . '_' . substr($path, 0, strpos($path, '.'));
//            echo $secdDir;
//            echo PHP_EOL;
//        }
//        echo 'http://misc.kimiss.com/common/?c=' . $control;
//        echo PHP_EOL;
        $templates = $matches[1];
        foreach($templates as $key => $value) {
            $templates[$key] = '/export/manager/misc-common/template_dir/' . $value . '.html';
        }
        $urls[] = array(
            'url' => 'http://misc.kimiss.com/common/?c=' . $control, 
            'file' => '/export/manager/misc-common/' . $filename,
            'templates' => $templates
                );
    }
    closedir($fdir);
//    echo PHP_EOL;
}

var_export($urls);

 

posted on 2015-06-18 17:54  bandbandme  阅读(750)  评论(0编辑  收藏  举报