PHP uses the copy function to implement the update configuration file

Source: Internet
Author: User
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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.