教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php脚本在每个目录生成index.html

php脚本在每个目录生成index.html

发布时间:2011-05-06   编辑:jiaochengji.com
教程集为您提供php脚本在每个目录生成index.html等资源,欢迎您收藏本站,我们将为您提供最新的php脚本在每个目录生成index.html资源

这个php脚本在每个目录生成index.html,可以防止网站源码以及网站资源被窥探。尤其像years4这样的黑客 本程序参考了xuxu的一个目录遍历函数 源代码如下:

<?php
//配置
$root_dir = '/www/caitupian'; // 根目录
$default_content = ' ';  //生成的index.html文件默认内容
//开始执行
function rscandir($base = '',$return = 'all', &$data = array()  ) {
	$ds = '/'; // DIRECTORY_SEPARATOR
	$base = rtrim($base,$ds).$ds;
	$array = array_diff(scandir($base), array('.', '..', '.svn'));
	foreach ($array as $value) {
		if (is_dir($base . $value)) {
			if($return != 'file')
			$data[] = $base . $value . $ds;
			$data = rscandir($base . $value . $ds, $return, $data );
		} elseif (is_file($base . $value)) {
			if($return == 'dir') continue;
			$data[] = $base . $value;
		}
	}
	return $data;
}
$dirs = rscandir($root_dir, 'dir');
$current_path = str_replace('\\', '/', dirname(__FILE__));
$source_path = $current_path.'/index.html';
file_put_contents($source_path, $default_content);

foreach ($dirs as $d)
{
	copy($source_path, $d.'index.html');
}

本程序可以直接在浏览器里运行或者在命令行下运行。

您可能感兴趣的文章:
windowsXP环境下apache2.2 mysql5.1 php5.2 phpmyadmin2.
WINXp,windows2000下配置apache2.0.52 php5.0.2 mysql4.0
dir显示目录结构树的批处理脚本
PHP中使用smarty生成静态文件的例子
php注意事项
php session实现多级目录存放
PHP生成静态网页的方法
php生成静态页面的详细教程
PHP的安装
创建ASP.NET数据存储层(7)

关键词: php  目录  脚本  生成  其他web相关   
[关闭]
~ ~