How to update the configuration file using the COPY function in php

Source: Internet
Author: User

How to update the configuration file using the COPY function in php

This example describes how php updates the configuration file using the COPY function. Share it with you for your reference. The details are 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

21

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

<? Php

/*

* File: _ saveconfig. php

*

* Modified: 2010-7-11

* By: liulang

* Note: two files are involved: _ saveconfig. php and config. php. When updating some global configuration variables in the background,

* Change the config. php file in the background and then use this file to change the config. php file in the foreground (the front and back ends are all the same ),

* This is a method I have used and I think it is good to 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 ('sitekeyword', $ gSite ['sitekeyword']),

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

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

<? Php

/*

* 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', // host name

'User' => 'root', // user Name

'Pwd' => '', // Password

'Db' => 'sino ', // Database Name

'Prefix' => 'sin _ '// database prefix

);

$ GSite = array

(

'Sitename' => 'Company name ',

'Sitenameen' => 'we are the company ',

'Sitekeyword' => 'medicines, pharmaceuticals ',

'Sitedescription' => 'Company name is a 00 company'

);

$ GUpload = array

(

'Dir' => 'uploads ',

'Imagewidth' => '123 ',

'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 will help you with php programming.

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.