Write to php file with php script or create new file, it is possible?

01-28-06, 02:39 PM
|
|
Newbie Coder
|
|
Join Date: Apr 2005
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Write to php file with php script or create new file, it is possible?
Hello,
I've a config.php file that contains the following:
$dbhost = "localhost";
$dbuname = "root";
$dbpass = "";
$dbname = "test";
$prefix = "test";
$user_prefix = "test";
$dbtype = "MySQL";
And I've a script that gives these variables right values/texts. The problem is that I can't figure out how to insert the new values into the config.php file without having to open it manually and insert the text myself (I'm working on a installation script). Is it possible to insert the right values into the config.php file without editing it manually?
So for example the $dbname = "test"; is changed to the value I writed in the installation script like for example $dbname = "right";.
Or is it possible to just create a new config file with the variables from the script? (the script creates a new config file with the things I want)?
Best Regards
Oskar R
|

01-28-06, 03:48 PM
|
 |
Community Leader
|
|
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
|
|
|
|

01-28-06, 05:15 PM
|
|
Newbie Coder
|
|
Join Date: Jan 2006
Location: Baghdad, Iraq
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
nico_swd method is very good, but remember to give 777 permission to config.php
__________________
e-Haw!
|

01-28-06, 06:44 PM
|
|
Newbie Coder
|
|
Join Date: Apr 2005
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello,
I can't get the values to add, the output (config.php) always looks like this:
Without any values, what did I do wrong?
Example script?
Best Regards
Oskar R
|

01-28-06, 07:01 PM
|
|
Wannabe Coder
|
|
Join Date: Nov 2003
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
Originally Posted by Oras
nico_swd method is very good, but remember to give 777 permission to config.php
|
Don't give 777 permissions to the config file, give 666 permissions to config file. There is no need to allow the file to be executed.
|

01-28-06, 07:01 PM
|
 |
Community Leader
|
|
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
|
|
|
|

01-28-06, 08:11 PM
|
|
Aspiring Coder
|
|
Join Date: Jan 2006
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
Originally Posted by Oskare100
Hello,
I've a config.php file that contains the following:
$dbhost = "localhost";
$dbuname = "root";
$dbpass = "";
$dbname = "test";
$prefix = "test";
$user_prefix = "test";
$dbtype = "MySQL";
And I've a script that gives these variables right values/texts. The problem is that I can't figure out how to insert the new values into the config.php file without having to open it manually and insert the text myself (I'm working on a installation script). Is it possible to insert the right values into the config.php file without editing it manually?
So for example the $dbname = "test"; is changed to the value I writed in the installation script like for example $dbname = "right";.
Or is it possible to just create a new config file with the variables from the script? (the script creates a new config file with the things I want)?
Best Regards
Oskar R
|
Yes you can but you have to re-write the config file with the new variables in it. Like some of the others have explained above, but you must make sure that the config file matches the original layout etc.
|

01-31-06, 03:41 PM
|
 |
Newbie Coder
|
|
Join Date: Jan 2006
Location: England
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That'll give it the same formatting structure.
|

02-02-06, 09:32 AM
|
 |
Aspiring Coder
|
|
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What I did with mine..
I made it read each variable in the file, then output boxes for all of them in the order it reads it, or defined categories then sort them...
Take the input, and write to the file using the form input names as the variables, and if you want to add a new, just add it to the end of the file..
|

08-14-08, 06:45 AM
|
|
New Member
|
|
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm sorry, if we don't have the privilage to access the file permission, how can we write the file?
Also i'm wondering if we can create the file while the directory permission isn't 777. How can we do that??
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|