srinivas6203 Posted August 3, 2008 Share Posted August 3, 2008 i am doing website using php and mysql on Linux. I want to generate .conf file using php and mysql. i want to fetch values from database table and generate conf file. Quote Link to comment https://forums.phpfreaks.com/topic/117932-solved-generate-conf-file-using-php-and-mysql/ Share on other sites More sharing options...
wildteen88 Posted August 3, 2008 Share Posted August 3, 2008 Use file_put_contents to create and populate the .conf file, what you're trying to achieve is the same thing as displaying the data to the webpage (using echo or print) except your writing data to a file. Quote Link to comment https://forums.phpfreaks.com/topic/117932-solved-generate-conf-file-using-php-and-mysql/#findComment-606614 Share on other sites More sharing options...
ShaunO Posted August 3, 2008 Share Posted August 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117932-solved-generate-conf-file-using-php-and-mysql/#findComment-606624 Share on other sites More sharing options...
srinivas6203 Posted August 4, 2008 Author Share Posted August 4, 2008 Thanks for your reply friends. Can you send me scripts please. Quote Link to comment https://forums.phpfreaks.com/topic/117932-solved-generate-conf-file-using-php-and-mysql/#findComment-607267 Share on other sites More sharing options...
revraz Posted August 4, 2008 Share Posted August 4, 2008 No, but you can look at the PHP manual to learn how to use the functions. Quote Link to comment https://forums.phpfreaks.com/topic/117932-solved-generate-conf-file-using-php-and-mysql/#findComment-607269 Share on other sites More sharing options...
srinivas6203 Posted August 4, 2008 Author Share Posted August 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117932-solved-generate-conf-file-using-php-and-mysql/#findComment-607283 Share on other sites More sharing options...
srinivas6203 Posted August 4, 2008 Author Share Posted August 4, 2008 how can i change file permissions Quote Link to comment https://forums.phpfreaks.com/topic/117932-solved-generate-conf-file-using-php-and-mysql/#findComment-607317 Share on other sites More sharing options...
srinivas6203 Posted August 4, 2008 Author Share Posted August 4, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/117932-solved-generate-conf-file-using-php-and-mysql/#findComment-607389 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.