php 程序安装的一些技巧和常用方法
开发好的网站系统,使用配置安装
1.判断是否安装
if (file_exists('./install.lock')) {
echo '
你已经安装过该系统,如果想重新安装,请先删除站点install目录下的 install.lock 文件,然后再安装。
';
exit;
}
2.判断php版本
if (PHP_EDITION > phpversion()){
header("Content-type:text/html;charset=utf-8");
exit('您的php版本过低,不能安装本软件,请升级到'.PHP_EDITION.'或更高版本再安装,谢谢!');
}
3.一些常量定义
define("CRMEB_VERSION", '20180601');
date_default_timezone_set('PRC');
error_reporting(E_ALL & ~E_NOTICE);
header('Content-Type: text/html; charset=UTF-8');
define('SITE_DIR', _dir_path(substr(dirname(__FILE__), 0, -8)));//入口文件目录
define('APP_DIR', _dir_path(substr(dirname(__FILE__), 0, -15)));//项目目录
4.安装步骤定义和swich
$steps = array(
'1' => '安装许可协议',
'2' => '运行环境检测',
'3' => '安装参数设置',
'4' => '安装详细过程',
'5' => '安装完成',
);
switch ($step) {
case '1':
include_once ("./templates/step1.php");
exit();
case '2':
......
5.定义好输出的变量,引入模板
//必须开启函数
if(function_exists('file_put_contents')){
$file_put_contents = '[√]开启 ';
}else{
$file_put_contents = '[×]关闭';
$err++;
}
if(function_exists('imagettftext')){
$imagettftext = '[√]开启 ';
}else{
$imagettftext = '[×]关闭';
$err++;
}
include_once ("./templates/step2.php");
exit();
case '3':
6.定义安装中使用的函数
//写入安装信息
function installlog(){
$mt_rand_str = sp_random_string(6);
$str_constant = "
7.获取环境配置方法:ini_get()
if (ini_get('file_uploads')) {
$uploadSize = '√ ' . ini_get('upload_max_filesize');
} else {
$uploadSize = '√禁止上传';
}
8.获取函数或者扩展是否开启:function_exists()
if (function_exists('session_start')) {
$session = '√ 支持';
} else {
$session = '√ 不支持';
$err++;
}
if(function_exists('curl_init')){
$curl = '[√]支持 ';
}else{
$curl = '[×]不支持';
$err++;
}
if(function_exists('file_put_contents')){
$file_put_contents = '[√]开启 ';
}else{
$file_put_contents = '[×]关闭';
$err++;
}
if(function_exists('imagettftext')){
$imagettftext = '[√]开启 ';
}else{
$imagettftext = '[×]关闭';
$err++;
}
9.目录或者文件的读写权限判断:is_readable()、
is_writable()
if(is_readable($Testdir)){
$r = '√可读' ;
}else{
$r = '√不可读';
}
//判断权限
function testwrite($d) {
if(is_file($d)){
if(is_writeable($d)){
return true;
}
return false;
}else{
$tfile = "_test.txt";
$fp = @fopen($d . "/" . $tfile, "w");
if (!$fp) {
return false;
}
fclose($fp);
$rs = @unlink($d . "/" . $tfile);
if ($rs) {
return true;
}
return false;
}
}
请先登录后再评论登录