Jump to content

[SOLVED] generate .conf file using php and mysql


srinivas6203

Recommended Posts

Woot wildteen88, nice one, never seen file_put_contents() before since it's somewhat new.

I've just been using fopen/fwrite/fclose which by the looks of things the OP will still need to use if they are still using PHP4

 

He is right though, just use file_put_contents() and instead of echo to the page, add everything into a variable and use that function. Make sure you add "\n" to the end of lines in any strings that need them.

I tried by the using of following script. But i got errors.

 

$path="var/www/files/";

$file=$path."test_file.txt";

$fp=fopen($file,"w");

//echo file_put_contents($file,"Hello World. Testing!");

fwrite($fp, 'sample data');

fclose($fp);

 

I got following errors:

 

Warning: fopen(var/www/files/test_file.txt) [function.fopen]: failed to open stream: No such file or directory in /var/www/admin/conf_changes.php on line 11

 

Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/admin/conf_changes.php on line 13

 

Warning: fclose(): supplied argument is not a valid stream resource in /var/www/admin/conf_changes.php on line 14

 

Please help me out.

Problem was solved by using following script. Thanx for every cooperation.

 

$dh="/var/www/admin/";

`sudo chmod 777 $dh`;

$file="test.txt";

$fullpath=$dh.$file;

`sudo chmod 777 $fullpath`;

$create_file=fopen($fullpath,"w+");

$stringData = 'sample';

fwrite($create_file, $stringData);

fclose($create_file);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.