<?php error_reporting(E_ALL); header('Content-Type: text/html; charset=utf-8'); session_start(); $ds = DIRECTORY_SEPARATOR; // too much typing ;) if (!isset($_GET['step'])) { $step = 1; } else { $step = $_GET['step']; } switch ($step) { case '1': if ((strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')) { $error = array(); if (phpversion() < '5.0') { $error['message'] = '警告: 你需要使用PHP5以上的版本以便正常工作!'; } if (ini_get('register_globals')) { $error['message'] = '警告:演示程序要求将register_globals设置为Off!'; } if (!ini_get('file_uploads')) { $error['message'] = '警告:file_uploads需要设置为On!'; } if (ini_get('session.auto_start')) { $error['message'] = '警告:演示程序需要将session.auto_start设置为Off!'; } if (!extension_loaded('mysql')) { $error['message'] = '警告:MySQL extention 需要装入,请修改php.ini相关参数!'; } if (!extension_loaded('gd')) { $error['message'] = '警告:GD extention 需要装入,请修改php.ini相关参数!'; } if (!is_writable(dirname(__FILE__) . '/../config.php')) { $error['message'] = '警告:config.php在安装时必须设置成可读写状态!'; } if (!is_writable(dirname(__FILE__) . '/../APP')) { $error['message'] = '警告:APP 目录在安装时必须设置成可读写状态!'; } if (!is_writable(dirname(__FILE__) . '/../images')) { $error['message'] = '警告:Images 目录在安装时必须设置成可读写状态!'; } if (!is_writable(dirname(__FILE__) . '/../templates')) { $error['message'] = '警告:templets 目录在安装时必须设置成可读写状态!'; } if (!is_writable(dirname(__FILE__) . '/../templates_c')) { $error['message'] = '警告:templets_c 目录在安装时必须设置成可读写状态!'; } if (!is_writable(dirname(__FILE__) . '/../upload')) { $error['message'] = '警告:upload 目录在安装时必须设置成可读写状态!'; } if (!$error) { header('Location: index.php?step=2'); exit(); } } ob_start(); ?> <form action="index.php?step=1" method="post" enctype="multipart/form-data"> <div id="header" >步骤 1 - 准备安装</div> <div id="content"> <?php if (isset($error['message'])) { ?> <div class="warning"><?php echo $error['message']; ?></div> <?php } ?> <br>1. 请调整php.ini相关参数确保安装需要需要.</br> <table width="100%"> <tr bgcolor="597380"> <th width="35%" align="left">PHP 参数</th> <th width="25%" align="left">当前</th> <th width="25%" align="left">需要</th> <th width="15%" align="left">状态</th> </tr> <tr bgcolor="#AFC4CF"> <td>PHP 版本:</td> <td><?php echo phpversion(); ?></td> <td>5.0+</td> <td><?php echo (phpversion() >= '5.0' ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td> </tr> <tr bgcolor="#AFC4CF"> <td>Register Globals:</td> <td><?php echo (ini_get('register_globals') ? 'On' : 'Off'); ?></td> <td>Off</td> <td><?php echo (!ini_get('register_globals') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td> </tr> <tr bgcolor="#AFC4CF"> <td>File Uploads:</td> <td><?php echo (ini_get('file_uploads') ? 'On' : 'Off'); ?></td> <td>On</td> <td><?php echo (ini_get('file_uploads') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td> </tr> <tr bgcolor="#AFC4CF"> <td>Session Auto Start:</td> <td><?php echo (ini_get('session.auto_start') ? 'On' : 'Off'); ?></td> <td>Off</td> <td><?php echo (!ini_get('session.auto_start') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td> </tr> </table> <br>2. 请确定下列PHP扩展已安装.</br> <table width="100%"> <tr bgcolor="597380"> <th width="35%" align="left">PHP 扩展</th> <th width="25%" align="left">当前设置</th> <th width="25%" align="left">需要设置</th> <th width="15%" align="left">状态</th> </tr> <tr bgcolor="#AFC4CF"> <td>MySQL:</td> <td><?php echo (extension_loaded('mysql') ? 'On' : 'Off'); ?></td> <td>On</td> <td><?php echo (extension_loaded('mysql') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td> </tr> <tr bgcolor="#AFC4CF"> <td>GD:</td> <td><?php echo (extension_loaded('gd') ? 'On' : 'Off'); ?></td> <td>On</td> <td><?php echo (extension_loaded('gd') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td> </tr> </table> <br>3. 请确定你有下列文件的读写权限.</br> <table width="100%"> <tr bgcolor="597380"> <th align="left">文件</th> <th width="15%" align="left">状态</th> </tr> <tr bgcolor="#AFC4CF"> <td><?php echo realpath(dirname(__FILE__) . '/../config.php'); ?></td> <td><?php echo (is_writable(dirname(__FILE__) . '/../config.php') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td> </tr> </table> <br>4. 请确定你有下列目录的读写权限.</br> <table width="100%"> <tr bgcolor="597380"> <th align="left">目录</th> <th width="15%" align="left">状态</th> </tr> <tr bgcolor="#AFC4CF"> <td><?php echo realpath(dirname(__FILE__) . '/../APP') . '/'; ?></td> <td><?php echo (is_writable(dirname(__FILE__) . '/../APP') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td> </tr> <tr bgcolor="#AFC4CF"> <td><?php echo realpath(dirname(__FILE__) . '/../images') . '/'; ?></td> <td><?php echo (is_writable(dirname(__FILE__) . '/../images') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td> </tr> <tr bgcolor="#AFC4CF"> <td><?php echo realpath(dirname(__FILE__) . '/../templates') . '/'; ?></td> <td><?php echo (is_writable(dirname(__FILE__) . '/../templates') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td> </tr> <tr bgcolor="#AFC4CF"> <td><?php echo realpath(dirname(__FILE__) . '/../templates_C') . '/'; ?></td> <td><?php echo (is_writable(dirname(__FILE__) . '/../templates_C') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td> </tr> <tr bgcolor="#AFC4CF"> <td><?php echo realpath(dirname(__FILE__) . '/../upload') . '/'; ?></td> <td><?php echo (is_writable(dirname(__FILE__) . '/../upload') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td> </tr> </table> </div> <div id="footer"> <input type="submit" value="继续" /> </div> </form> <?php $content = ob_get_contents(); ob_end_clean(); break; case '2': if ($_POST) { $error = array(); if (!$_POST['db_host']) { $error['db_host'] = '* Host 必须填写!'; } if (!$_POST['db_user']) { $error['db_user'] = '* User 必须填写!'; } if (!$_POST['db_name']) { $error['db_name'] = '* Database 名称必须填写!'; } if (!$error) { if (!$connection = @mysql_connect($_POST['db_host'], $_POST['db_user'], $_POST['db_password'])) { $error['message'] = '出错: 不能连接到数据库,请确认主机名称,用户名,密码是否正确!' . "\n"; } else { if (!@mysql_select_db($_POST['db_name'], $connection)) { $error['message'] = '出错: 数据库不存在!' . "\n"; } } } if (!$error) { mysql_query("set character set utf8", $connection); $file = dirname(__FILE__) . $ds.'openframeworkexample.sql'; if ($sql = file($file)) { //read a file into a array $query = ''; foreach($sql as $line) { $tsl = trim($line); if (($sql != '') && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != '#')) { $query .= $line; if (preg_match('/;\s*$/', $line)) { $result = mysql_query($query, $connection); if (!$result) { die(mysql_error()); } $query = ''; } } } mysql_close($connection); } else { $error['message'] = '出错: 安装SQL文件 ' . $file . ' 不存在!' . "\n"; } } if (!$error) { $_SESSION['db_host'] = $_POST['db_host']; $_SESSION['db_user'] = $_POST['db_user']; $_SESSION['db_password'] = $_POST['db_password']; $_SESSION['db_name'] = $_POST['db_name']; header('Location: index.php?step=3'); exit(); } } ob_start(); ?> <form action="index.php?step=2" method="post" enctype="multipart/form-data"> <div id="header">步骤 2 - 数据库信息</div> <div id="content"> <?php if (isset($error['message'])) { ?> <div class="warning"><?php echo $error['message']; ?></div> <?php } ?> <p>请输入你的数据库连接信息.</p> <table> <tr bgcolor="#AFC4CF"> <td width="185"><span class="required">*</span>主机名称:</td> <td><?php if (isset($_POST['db_host'])) { ?> <input type="text" name="db_host" value="<?php echo $_POST['db_host']; ?>" /> <?php } elseif (isset($_SESSION['db_host'])) { ?> <input type="text" name="db_host" value="<?php echo $_SESSION['db_host']; ?>" /> <?php } else {?> <input type="text" name="db_host" value="localhost" /> <?php } ?> <?php if (isset($error['db_host'])) { ?> <span class="required"><?php echo $error['db_host']; ?></span> <?php } ?></td> </tr> <tr bgcolor="#AFC4CF"> <td><span class="required">*</span>用户名:</td> <td><input type="text" name="db_user" value="<?php echo (isset($_POST['db_user']) ? $_POST['db_user'] : @$_SESSION['db_user']); ?>" /> <?php if (isset($error['db_user'])) { ?> <span class="required"><?php echo $error['db_user']; ?></span> <?php } ?></td> </tr> <tr bgcolor="#AFC4CF"> <td><span class="required">*</span>密码:</td> <td><input type="text" name="db_password" value="<?php echo (isset($_POST['db_password']) ? $_POST['db_password'] : @$_SESSION['db_password']); ?>" /> <?php if (isset($error['db_password'])) { ?> <span class="required"><?php echo $error['db_password']; ?></span> <?php } ?></td> </tr> <tr bgcolor="#AFC4CF"> <td><span class="required">*</span>数据库名称:</td> <td><input type="text" name="db_name" value="<?php echo (isset($_POST['db_name']) ? $_POST['db_name'] : @$_SESSION['db_name']); ?>" /> <?php if (isset($error['db_name'])) { ?> <span class="required"><?php echo $error['db_name']; ?></span> <?php } ?></td> </tr> </table> </div> <div id="footer"> <input type="submit" value="继续" /> </div> </form> <?php $content = ob_get_contents(); ob_end_clean(); break; case '3': if ((strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')) { $error = array(); $server = $_SERVER['HTTP_HOST'] . substr($_SERVER['PHP_SELF'], 0 , (strpos($_SERVER['PHP_SELF'], 'install/index.php'))); $config = realpath(dirname(__FILE__) . '/../config.php'); if (is_writable($config)) { $output = '<?php' . "\n"; $output .= '// HTTP' . "\n"; $output .= 'define(\'HTTP_SERVER\', \'http://' . $server . '\');' . "\n"; $output .= 'define(\'HTTP_IMAGE\', \'http://' . $server . 'image/\');' . "\n\n";
$output .= '// HTTPS' . "\n"; $output .= 'define(\'HTTPS_SERVER\', \'\');' . "\n"; $output .= 'define(\'HTTPS_IMAGE\', \'\');' . "\n\n"; $output .= '// DIR' . "\n"; $output .= 'define(\'DIR_APP\', \'' . realpath(dirname(__FILE__) . '/..') . '/APP/\');' . "\n"; $output .= 'define(\'DIR_UPLOAD\', \'' . realpath(dirname(__FILE__) . '/..') . '/upload/\');' . "\n"; $output .= 'define(\'DIR_IMAGES\', \'' . realpath(dirname(__FILE__) . '/..') . '/imageS/\');' . "\n"; $output .= 'define(\'DIR_LIBRARY\', \'' . realpath(dirname(__FILE__) . '/..') . '/library/\');' . "\n"; $output .= 'define(\'DIR_TEMPLATES\', \'' . realpath(dirname(__FILE__) . '/..') . '/templates/\');' . "\n"; $output .= 'define(\'DIR_TEMPLATES_C\', \'' . realpath(dirname(__FILE__) . '/..') . '/templates_c/\');' . "\n"; $output .= '// DB' . "\n"; $output .= 'define(\'DB_HOST\', \'' . $_SESSION['db_host'] . '\');' . "\n"; $output .= 'define(\'DB_USER\', \'' . $_SESSION['db_user'] . '\');' . "\n"; $output .= 'define(\'DB_PASSWORD\', \'' . $_SESSION['db_password'] . '\');' . "\n"; $output .= 'define(\'DB_NAME\', \'' . $_SESSION['db_name'] . '\');' . "\n"; $output .= '?>'; $file = fopen($config, 'w'); fwrite($file, $output); fclose($file); } else { $error['message'] = '错误: 不能对config.php进行设置,请检查你是否有config目录的读写权限: ' . $config . "\n"; } if (!$error) { $server = substr($_SERVER['PHP_SELF'], 0 , (strpos($_SERVER['PHP_SELF'], 'install/index.php'))); header('Location: '.$server); exit(); } } //header('Location: index.php?step=4'); //exit(); ob_start(); ?> <form action="index.php?step=3" method="post" enctype="multipart/form-data"> <div id="header">步骤 3 - 安装完成!</div> <div id="content"> <p>恭喜你! 演示程序已经成功地安装在你的电脑上.</p> <div class="warning">不要忘记删除你的安装目录!</div> </div> <div id="footer"> <input type="submit" value="继续" /> </div> </form> <?php $content = ob_get_contents(); ob_end_clean(); break; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>系统安装</title> <base href="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['PHP_SELF'], 0 , (strrpos($_SERVER['PHP_SELF'], "/") + 1)); ?>"> <link rel="stylesheet" type="text/css" href="stuff/stylesheet.css" /> </head> <body> <div id="container"><?php echo $content; ?></div> </body> </html>
|