Hi all,
I have some code which is meant to search through a configuration file for a certain string "$ASSET_DB_NAME = "";" If it finds it then it replaces it with $ASSET_DB_NAME = to a string. When I run the script below it appends at the end of the file "database_config.inc.tmp.php" the first line of it, which is "<?php".
<?php
require_once ("config-files/path_info.inc.php");
function update_config_file ($asset_db_name) {
global $CONFIG_PATH;
$config_file = fopen ($CONFIG_PATH.'database_config.inc.tmp.php', 'a+') or die ($php_errormsg);
$search_file = fread ($config_file, filesize ($CONFIG_PATH.'database_config.inc.tmp.php')) or die ($php_errormsg);
$search_file = preg_replace ('/\$ASSET_DB_NAME = \"\";/', '$ASSET_DB_NAME = \"'.$asset_db_name.'\";', $search_file);
// seek back to the beginning of the file and write the string
rewind ($config_file);
if ( -1 == fwrite ($config_file, $search_file) ) { die ($php_errormsg); }
// adjust the file's length to just whats been written
ftruncate ($config_file, ftell ($config_file)) or die ($php_errormsg);
fclose ($config_file) or die ($php_errormsg);
} // update_config_file ($asset_db_name)
update_config_file ("test");
?>
I got most of this function from a book so I admit I do not understand it fully. Does anyone know what is going wrong?
Cheers
SOL