Recent Topics

1 Jun 25, 2011 20:39    

Hi, I would like to know how to write the default settings to a .txt file.

I already know how to write it to file and also how to read it from file, what I am struggling with is writing the new values to a file. I either get an error or a empty string. Here is a sample code.

	function GetDefaultSettings( & $params )
					{ 

$plug_url = $this->get_plugin_url();
$currentDirectory = array_pop(explode("/", getcwd()));	
$b_url = $currentDirectory.''.$plug_url.'settings.txt'; 
 $fh = fopen($b_url, 'r') or die("can't open file"); 
 $Data_url_stat = fread($fh, 512); 
 fclose($fh);
 
		if(empty($Data_url_stat))
		{$blog_url = $_SERVER['HTTP_HOST'];}
		else {$blog_url = $Data_url_stat;}

$r = array(	

'blog_url' => array(
					'label' => 'Site Url',
					'type' => 'text',
					'size' => 35,
					'defaultvalue' => $blog_url, 
					'note' => T_('If your default url is incorrect please change it here.'),
					),);

$currentDirectory = array_pop(explode("/", getcwd()));	
			$b_url = $currentDirectory.''.$plug_url.'settings.txt';	
			$fh = fopen($b_url, 'w') or die("can't open file");


/* HOW TO CALL THE NEW DEFINED VALUE */		
$blog_url_n = $this->Settings->get('blog_url');  // Not Working
$blog_url_n = $this->settings['blog_url'];    // Not Working - Returned empty
/* HOW TO CALL THE NEW DEFINED VALUE */

			$stringData = $blog_url_n;
			fwrite($fh, $stringData);
			fclose($fh);

		return $r;
	}

Any help would be appreciated.

2 Jun 26, 2011 01:51

Hi, I managed to resolve the problem so:

	function AdminBeginPayload()
	{
		global $Plugins;
			
            $plug_url = $this->get_plugin_url();
			$currentDirectory = array_pop(explode("/", getcwd()));	
			$b_url = $currentDirectory.''.$plug_url.'settings.txt';	
			$fh = fopen($b_url, 'w') or die("can't open file");
			$blog_url_n = $this->Settings->get('blog_url');
			fwrite($fh, $blog_url_n);
			fclose($fh);
	}

3 Jun 26, 2011 04:58

This is a better way of getting current dir

$b_url = dirname(__FILE__).'/settings.txt';

4 Jun 26, 2011 05:10

Thanks Alex, have actually been struggling with that. (:


Form is loading...