PHP How to update a configuration file using the Copy function _php Tutorial

Source: Internet
Author: User

How PHP uses the copy function to update a configuration file


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:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

/*

* File: _saveconfig.php

*

* MODIFIED:2010-7-11

* By:liulang

* Description: Involves two files: _saveconfig.php and config.php When you update some of the global configuration variables in the background,

* Change the background of the config.php and then through this file to change the foreground config.php file (the former background files are the same),

* This is one of the methods I have used, I think it's not bad, take it out and share it with you

*

* created:2010-6-20

* By:liulang (xujiaphp@gmail.com)

*

*/

$srcFile = '. /'. $dRootDir. ' #data/config.php ';

$dstFile = $dRootDir. ' config.php ';

$content = file_get_contents ($srcFile);

$arr = array

(

Array (' SITENAME ', $gSite [' SITENAME ']),

Array (' Sitenameen ', $gSite [' Sitenameen ']),

Array (' Sitekeywords ', $gSite [' sitekeywords ']),

Array (' Sitedescription ', $gSite [' sitedescription ']),

Array (' URLPrefix ', $gUrlPrefix),

Array (' Dbhost ', $gDb [' Host ']),

Array (' DBUSER ', $gDb [' User ']),

Array (' Dbpwd ', $gDb [' pwd ']),

Array (' DBNAME ', $gDb [' DB ']),

Array (' Dbprefix ', $gDb [' prefix ']),

Array (' dir ', $gUpload [' dir ']),

Array (' ImageWidth ', $gUpload [' imagewidth ']),

Array (' ImageHeight ', $gUpload [' ImageHeight ']),

Array (' ContactUs ', $contactus),

Array (' Menuhiddendiv ', $menuhiddendiv),

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:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

/*

* File:config.php

*

* modified:2010-09-20

* By:admin

*

* created:2010-6-20

* By:liulang (xujiaphp@gmail.com)

*

*/

$gVersion = ' 1.0 ';

$gDb = array

(

' Host ' = ' localhost ',//hostname

' User ' = ' root ',//username

' pwd ' and ' = ',//password

' db ' = ' Sino ',//database name

' Prefix ' = ' sin_ '//Database prefix

);

$gSite = array

(

' SiteName ' = ' Company name ',

' Sitenameen ' and ' We're the company ',

' sitekeywords ' = ' drugs, pharmaceuticals, pharmaceuticals ',

' Sitedescription ' = ' Company name is a company engaged in 00 aspects '

);

$gUpload = array

(

' dir ' = ' uploads ',

' ImageWidth ' = ' 120 ',

' ImageHeight ' = ' * '

);

$contactus = ";

$menuhiddendiv = "";

$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 '");

?>

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1018367.html www.bkjia.com true http://www.bkjia.com/PHPjc/1018367.html techarticle How PHP updates a configuration file using the Copy function This article describes how PHP uses the copy function to update a configuration file. Share to everyone for your reference. Specific as follows: _saveconfig.ph ...

  • 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.