This article mainly introduces the method that PHP uses the copy function to update the configuration file, which involves the technique of updating the configuration information by the copy function. We hope to help you. This example describes how PHP updates a configuration file using the copy function. Share to everyone for your reference.
Specific as follows:
The _saveconfig.php file is as follows:
<?php/* * File: _saveconfig.php * * Description: Involves two files: _saveconfig.php and config.php when updating some global configuration variables in the background, * Change the background of the config.php and then through this file to change the foreground of the config.php file (the former background files are the same), * This is a method I have used, feel good, take it out to share with you * * */$srcFile = '. /'. $dRootDir. ' #data/config.php '; $dstFile = $dRootDir. ' config.php '; $content = file_get_contents ($srcFile); $arr = Array (' SITENAME ', $gSite [' SITENAME ']), array (' Sitenameen ', $gSite [' Sitenameen ']), array (' Sitek Eywords ', $gSite [' sitekeywords ']), array (' sitedescription ', $gSite [' sitedescription ']), array (' URLPrefix ', $gUrlPr Efix), Array (' Dbhost ', $gDb [' Host ']), array (' DBUSER ', $gDb [' User ']), array (' Dbpwd ', $gDb [' pwd ']), array (' D Bname ', $gDb [' DB ']), array (' Dbprefix ', $gDb [' prefix ']), Array (' dir ', $gUpload [' dir ']), array (' ImageWidth ', $gU pload[' ImageWidth '), Array (' ImageHeight ', $gUpload [' ImageHeight ']), array (' ContactUs ', $contactus), Array (' ME NUHIDDENP ', $MENUHIDDENP), Array (' THEME ', $gTheme), Array (' DATE ', date (' y-m-d ')), array (' USER ', $dAdminName)); for ($i = 0; $i < count ($arr), $i + +) {$content = Str_replace (' ~ ' ~ '. $arr [$i][0]. ' ~ ' ~ ', $arr [$i][1], $content); Copy ($dRootDir. ' config.php ', $dRootDir. ' bak.config.php '); Copy ($dRootDir. ' bak.config.php ', '. /'. $dRootDir. ' config.php '); $done = File_put_contents ($dstFile, $content); Copy ($dstFile, '.. /'. $dRootDir. ' config.php ');? >
The config.php configuration file is as follows:
<?php/* * * * * */ $gVersion = ' 1.0 '; $gDb = array ( ' host ' = ' localhost ', //hostname ' user ' = ' root ',// user name ' pwd ' = ', Password ' db ' = ' sino ', //database name ' prefix ' = ' sin_ ' //database prefix ); $gSite = array ( ' siteName ' = ' Company name ', ' sitenameen ' = ' We are the ', ' sitekeywords ' =& Gt ' Pharmaceuticals, pharmaceuticals, pharmaceuticals ', ' sitedescription ' + ' company name is a company engaged in 00 aspects ' ); $gUpload = array ( ' dir ' = ' uploads ', ' imagewidth ' = ' + ', ' imageheight ' = ' * ' ) ; $contactus = "; $MENUHIDDENP = ""; $FROMURL =$_server["Http_referer"]?$_server["Http_referer"]: $HTTP _server_vars["Http_referer"]; $dRootDir = '. /'; $conn = mysql_connect ($gDb [' Host '], $gDb [' User '], $gDb [' pwd ']; mysql_select_db ($gDb [' db ']) or Die (' Database connect error! '); mysql_query ("SET NAMES ' GBK '");?>
Related recommendations:
What is the purpose of the PHP copy () function?
PHP copy Function tutorial
Some of the neglected PHP functions (collation)