...

View Full Version : Appending PHP file with variables



Badman3k
05-21-2004, 12:11 PM
I'm trying to take data from a form and write them to a file 'config.inc.php' but without any luck.

The data is required to set up the configuration of a forum I'm building the installer for.

Below is my current code:


$sFilename = "../config.inc.php";
$sData = "\n\n// The following is from the install setup\n\n";
$sData .= "\$sPWBBName = ".$this->sBoardName."\n\n";
$sData .= "\$sSqlServer = ".$this->sDBHost."\n";
$sData .= "\$sSqlUser = ".$this->sDBUser."\n";
$sData .= "\$sSqlPassword = ".$this->sDBPass."\n";
$sData .= "\$sSqlDb = ".$this->sDBName."\n\n";
$sData .= "\$sTemplatePath = \"templates\"\n";
$sData .= "\$sIncPath = \"incs\"\n\n";
$sData .= "\$sPrefix = ".$this->sDBPrefix."\n";
// Lets write the data
$this->write_data($sFilename, $sData);

//Below is the function to write the data to the file...
function write_data($filename, $data)
{
//Appends file
$handle = fopen($filename, "a");
$finalwrite = fwrite($handle, $data);
fclose($handle);
return true;
}

Every time I try and run this, there doesn't appear to be any problems, apart from that it just won't write the data to the end of the file.

Does anyone have any idea as to what's going on? and do i need to add the end '?>' to the document?

Would it be easier to write a new php file to store the variables in?

Many thanks in advance

firepages
05-21-2004, 12:28 PM
try some basic error checking ..



<?
if( !is_writable( $filename ) ){
die( $filename .' is not writable' ) ;
}
?>


+ if on win32 try $handle = fopen($filename, "ab");

Badman3k
05-21-2004, 01:09 PM
Worked a bit on it after you posted, and the error messages pointed me in the direction that I needed to go.

Cheers :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum