php自动获取目录下的模板的代码

yipeiwu_com5年前PHP代码库
目录下必须有default.gif(此图为模板缩略图)的才为合法的模板
复制代码 代码如下:

function get_template ()
{
$template = array ();
$dir = CMS_ROOT.'/tpl/';
$n = 0;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file =='.' or $file == '..' or $file == '.svn')
{
continue;
}
if (is_dir ($dir.$file))
{
if (file_exists ($dir.$file.'/default.gif'))
{
$template[$n]['dir'] = $file;
$template[$n]['pic'] ='/tpl/'.$file.'/default.gif';
}
}
$n++;
}
closedir($dh);
}
}
return $template;
}

相关文章

PHP文件操作实例总结【文件上传、下载、分页】

PHP文件操作实例总结【文件上传、下载、分页】

本文实例讲述了PHP文件操作。分享给大家供大家参考,具体如下: 1、文件上传 上传域: input type="file" 普通文本框(text、password、textarea、r...

php中switch语句用法详解

本文介绍php中的switch语句的用法,它跟其他语句中的switch用法差不多的,但注意有有一个break语句。 PHP中switch语句的标准语法: switch (expre...

11个PHP 分页脚本推荐

11个PHP 分页脚本推荐

    Web开发中,分页设计必不可少。本文列举了10个PHP分页脚本,希望对你的web开发会有帮助。   列表中大部分,提供演示和代码下载。   1) My Paginat...

学习PHP的数组总结【经验】

PHP有很多关于数组的函数,方便数组操作。 定义: 数组每个实体包含两个项:key和value,可以通过查询键来获取其相应的值。这些键可以是数值(numerical)键或关联(assoc...

php 上一篇,下一篇文章实现代码与原理说明

实现原理: 就是对id对进行order by id desc 或 order by id asc进行排序,然后再判断比当前id> or小于当前文章id的相同栏目的文章。 实例的sq...