Php method for updating the configuration file using the COPY function _ PHP Tutorial

Source: Internet
Author: User
Php uses the COPY function to update the configuration file. Php use the COPY function to update the configuration file. This document describes how php uses the COPY function to update the configuration file. Share it with you for your reference. The details are as follows: _ saveconfig. ph php uses the COPY function to update the configuration file

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

/*

* 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 ', $ 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:

?

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

/*

* 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 = '';

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

?>

I hope this article will help you with php programming.

In this example, php uses the COPY function to update the configuration file. Share it with you for your reference. The details are 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.