网站安装程序

网站安装程序

1.is_writeable();
2.rename('原名','新名');
3.$resource=fopen($file_path,"w+"),
3.fwrite($resource,$config_str);

目录结构:
网站安装程序

install.php代码如下:

<?php
header("Content-Type:text/html;charset=utf-8");
$files_path="./data/config.php";
	if (!is_writeable($files_path)) {
		exit("please check right");
	}else {
		if (isset($_POST['install'])) {
			$config_str="<?php";
			$config_str.="\r\n";
			$config_str.='$mysql_host	=	"'.$_POST['db_host'].'";';
			$config_str.="\r\n";
			$config_str.='$mysql_user	=	"'.$_POST['db_user'].'";';
			$config_str.="\r\n";
			$config_str.='$mysql_pwd	=	"'.$_POST['db_pwd'].'";';
			$config_str.="\r\n";
			$config_str.='$mysql_name	=	"'.$_POST['db_name'].'";';
			$config_str.="\r\n";
			$config_str.='$mysql_tag	=	"'.$_POST['db_tag'].'";';
			$config_str.="\r\n";
			$config_str.="?>";
			$ff=fopen($files_path,"w+");
			fwrite($ff,$config_str);
		}
		require_once './data/config.php';
		if(!@$link=mysql_connect($mysql_host,$mysql_user,$mysql_pwd,$mysql_pwd)){
			echo "数据库连接失败!请返回上一页检查连接参数<a href='install.php'>返回修改</a>";
		}else{
			mysql_select_db($mysql_name);
			$sql_query[]="create table ".$mysql_tag."admin_log1 (
							id int(8) unsigned not null primary key auto_increment,
							username varchar(40) not null,
							types varchar(40) not null);";
			$sql_query[]="create table ".$mysql_tag."admin_log2 (
							id int(8) unsigned not null primary key auto_increment,
							username varchar(40) not null,
							types varchar(40) not null);";
			$sql_query[]="create table ".$mysql_tag."admin_log3 (
							id int(8) unsigned not null primary key auto_increment,
							username varchar(40) not null,
							types varchar(40) not null);";
			foreach ($sql_query as $value){
				mysql_query($value);
			}
			rename("install.php","install.lock");
			echo "<script type='text/javascript'>alert('install is ok');top.location.href='index.php';</script>";
		}	
	}
?>
<html>
<meta http-equiv="Content-Type" content="text/hrml;charset=utf-8" />
<head>
<title>install</title>
</head>
<body>
<form action="?" method="post"><br />
填写主机:<input type="text" name="db_host" value="" /><br />
用 户 名:<input type="text" name="db_user" value="root" /><br />
密   码:<input type="password" name="db_pwd" value="" /><br />
数据库名:<input type="text" name="db_name" value="install" /><br />
数据前缀:<input type="text" name="db_tag" value="p_" /><br />
<!--<input type="submit" name="install" value="install" />-->
<button type="submit" name="install">下一步</button>
</form>
</body>
</html>



你可能感兴趣的:(php安装程序,网站安装程序,安装程序)