PHP制作程序安装

PHP制作程序安装<br /> /////////////////php部分///////////////////////<br /> &lt;?php<br /> $action=$_GET[&quot;action&quot;];<br /> if ($action==&quot;start&quot;)<br /> {<br /> $file_name=&quot;qiaso.sql&quot;; //要导入的SQL文件名<br /> $dbhost=$_POST[&quot;dbhost&quot;]; //数据库主机名<br /> $dbuser=$_POST[&quot;dbuser&quot;]; //数据库用户名<br /> $dbpass=$_POST[&quot;dbpass&quot;]; //数据库密码<br /> $dbname=$_POST[&quot;dbname&quot;]; //数据库名<br /> set_time_limit(0); //设置超时时间为0,表示一直执行。当php在safe mode模式下无效,此时可能会导致导入超时,此时需要分段导入<br /> $fp = @fopen($file_name, &quot;r&quot;) or die(&quot;不能打开SQL文件 $file_name&quot;);//打开文件<br /> $conn=mysql_connect($dbhost, $dbuser, $dbpass) or die(&quot;不能连接数据库 $dbhost&quot;);//连接数据库<br /> mysql_query(&quot;set names 'utf-8'&quot;,$conn); <br /> $sql=&quot;DROP DATABASE $dbname&quot;; //如果数据库存在,会删除.<br /> mysql_query($sql);<br /> $sql=&quot;CREATE DATABASE $dbname&quot;; //如果资料表存在,也会删除... 所以安全问题要考虑一下.<br /> mysql_query($sql);<br /> <br /> mysql_select_db($dbname) or die (&quot;不能打开数据库 $dbname&quot;);//打开数据库 <br /> mysql_query(&quot;SET NAMES 'GBK'&quot;);<br /> while($SQL=GetNextSQL()){<br /> if (mysql_query($SQL)){<br /> <br /> }<br /> }<br /> //echo &quot;导入完成&quot;; <br /> //echo &quot;&lt;/div&gt;&quot;;<br /> header(&quot;location:install.php?action=finish&quot;);<br /> fclose($fp) or die(&quot;Can't close file $file_name&quot;);//关闭文件<br /> mysql_close(); <br /> <br /> //开始写入Data/db_config.php<br /> $content.=&quot;&lt;?php&quot;.chr(13).chr(10);<br /> $content.=&quot;\$dbhost = '$dbhost';&quot;.chr(13).chr(10);<br /> $content.=&quot;\$dbuser = '$dbuser';&quot;.chr(13).chr(10);<br /> $content.=&quot;\$dbpw = '$dbpass';&quot;.chr(13).chr(10);<br /> $content.=&quot;\$dbname = '$dbname';&quot;.chr(13).chr(10);<br /> $content.=&quot;\$dbcharset = 'gbk';&quot;.chr(13).chr(10);<br /> $content.=&quot;\$dbpconnect = '0';&quot;.chr(13).chr(10);<br /> $content.=&quot;?&gt;&quot;;<br /> $fp=@fopen(&quot;include/db_config.php&quot;,&quot;w&quot;) or die(&quot;写方式打开文件失败,请检查程序目录是否为可写&quot;);//配置conn.php文件<br /> @fputs($fp,$content) or die(&quot;文件写入失败,请检查程序目录是否为可写&quot;); <br /> @fclose($fp);<br /> //end<br /> }<br /> <br /> function GetNextSQL() {<br /> global $fp;<br /> $sql=&quot;&quot;;<br /> while ($line = @fgets($fp, 40960)) {<br /> $line = trim($line);<br /> //以下三句在高版本php中不需要<br /> $line = str_replace(&quot;\\\\&quot;,&quot;\\&quot;,$line);<br /> $line = str_replace(&quot;\'&quot;,&quot;'&quot;,$line);<br /> $line = str_replace(&quot;\\r\\n&quot;,chr(13).chr(10),$line);<br /> // $line = stripcslashes($line);<br /> if (strlen($line)&gt;1) {<br /> if ($line[0]==&quot;-&quot; &amp;&amp; $line[1]==&quot;-&quot;) {<br /> continue;<br /> }<br /> }<br /> $sql.=$line.chr(13).chr(10);<br /> if (strlen($line)&gt;0){<br /> if ($line[strlen($line)-1]==&quot;;&quot;){<br /> break;<br /> }}<br /> }<br /> return $sql;<br /> }<br /> <br /> ?&gt;<br /> <br /> <br /> <br /> ////////////////////////////////////js检验表单数据///////////////<br /> &lt;script language=&quot;javascript&quot;&gt;<br /> function checkform()<br /> {<br /> if(installform.dbhost.value==&quot;&quot;)<br /> {<br /> alert(&quot;不能为空&quot;);<br /> installform.dbhost.focus();<br /> return false;<br /> }<br /> <br /> if(installform.dbuser.value==&quot;&quot;)<br /> {<br /> alert(&quot;不能为空&quot;);<br /> installform.dbuser.focus();<br /> return false;<br /> }<br /> <br /> if(installform.dbpass.value==&quot;&quot;)<br /> {<br /> alert(&quot;不能为空&quot;);<br /> installform.dbpass.focus();<br /> return false;<br /> }<br /> <br /> if(installform.dbname.value==&quot;&quot;)<br /> {<br /> alert(&quot;不能为空&quot;);<br /> installform.dbname.focus();<br /> return false;<br /> }<br /> <br /> }<br /> &lt;/script&gt;<br /> <br /> //////////////////////////////////////html///////////////////<br /> &lt;?php<br /> if($action==&quot;finish&quot;)<br /> {<br /> ?&gt;<br /> &lt;div class=&quot;tips&quot;&gt;已完成安装,请删除目录的install.php文件!&lt;br&gt;<br /> &lt;a href=&quot;index.html&quot;&gt;网站首页&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;admin/&quot;&gt;后台管理&lt;/a&gt;<br /> &lt;/div&gt;<br /> &lt;?php<br /> }<br /> else<br /> {<br /> ?&gt;<br /> &lt;form name=&quot;installform&quot; method=&quot;post&quot; action=&quot;?action=start&quot; onsubmit=&quot;return checkform();&quot;&gt;<br /> &lt;table width=&quot;600&quot; border=&quot;0&quot; align=&quot;center&quot; cellpadding=&quot;3&quot; cellspacing=&quot;1&quot; class=&quot;table&quot;&gt;<br /> &lt;tr&gt;<br /> &lt;td width=&quot;120&quot;&gt;数据库地址:&lt;/td&gt;<br /> &lt;td&gt;&lt;input name=&quot;dbhost&quot; type=&quot;text&quot; id=&quot;dbhost&quot; value=&quot;localhost&quot;&gt;&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;用户名:&lt;/td&gt;<br /> &lt;td&gt;&lt;input name=&quot;dbuser&quot; type=&quot;text&quot; value=&quot;root&quot;&gt;&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;密 码:&lt;/td&gt;<br /> &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;dbpass&quot;&gt;&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;数据库名称:&lt;/td&gt;<br /> &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;dbname&quot;&gt;&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;&amp;nbsp;&lt;/td&gt;<br /> &lt;td&gt;&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;提交&quot;&gt;&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;/table&gt;<br /> &lt;/form&gt;<br /> &lt;?php<br /> }<br /> ?&gt;
RangeTime:0.007472s
RangeMem:211.53 KB
返回顶部 留言