码迷,mamicode.com
首页 > Web开发 > 详细

php 访问目录,文件

时间:2015-06-18 19:23:26      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

 

$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);

 

php 访问目录,文件

标签:

原文地址:http://www.cnblogs.com/bandbandme/p/4586620.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!