tomfmason Posted July 11, 2006 Share Posted July 11, 2006 I am trying to create a script that will create a zone file in my dns directory (etc) and update my httpd.conf when I buy a new domain or add a subdomain.So far I am able to create the zone file just fine but I am unable to write anything to the file. I am using an example straight from the manual on [url=http://www.php.net/manual/en/function.fwrite.php]fwrite()[/url]. So far I get the following message [code]The file C:\windows\system32\dns\mysite.com.zone is not writable[/code]here is my fopen() file that creates the zone file[code=php:0]<?php$filename ="mysite.com.zone";fopen("C:\\windows\\system32\\dns\\etc\\$filename", "x+");?>[/code]And here is the fwrite() file[code=php:0]<?php$filename = 'C:\\windows\\system32\\dns\\mysite.com.zone';$somecontent = "$TTL 900 ; 900 seconds default record (T)ime (T)o (L)ive in cache@ SOA ns1 ( postmaster 2004041700 21600 1800 604800 900 @ NS ns1 @ NS ns2 @ A xx.xx.xxx.xx @ MX 10 mail ns1 A xx.xx.xxx.xx ns2 A xx.xx.xxx.xx mail A xx.xx.xxx.xx www A xx.xx.xxx.xx\n";// Let's make sure the file exists and is writable first.if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle);} else { echo "The file $filename is not writable";}?>[/code] I am also wondering how I would write or edit a specific line on a file?Any suggestions would be great. Quote Link to comment Share on other sites More sharing options...
tomfmason Posted July 11, 2006 Author Share Posted July 11, 2006 I fixed the fwrite() [b]The Fix[/b][code=php:0]<?php$filename = 'C:\\windows\\system32\\dns\\etc\mysite1.com.zone';$handle = fopen($filename, "x+");$somecontent = "\$TTL 900 @ SOA ns1 ( postmaster 2004041700 21600 1800 604800 900 @ NS ns1 @ NS ns2 @ A xx.xx.xxx.xx @ MX 10 mail ns1 A xx.xx.xxx.xx ns2 A xx.xx.xxx.xx mail A xx.xx.xxx.xx www A xx.xx.xxx.xx";fwrite($handle, $somecontent);fclose($handle);?> [/code]My qestion about write to a specific line is still unanswered. Also how would I reload bind via php? Quote Link to comment Share on other sites More sharing options...
rysio Posted January 15, 2007 Share Posted January 15, 2007 i've tried to modify the file dso that it also writes some more data, like this here - three digits: 257 (the choice of signs=>digits is random)well, it does write it, but the number 257 is written into the comments.txt file three times: like this:257text257257what to do to make it write the data only once?<?php$filename = 'comments.txt';$handle = fopen($filename, "a");$somecontent = "$comment\n257";fwrite($handle, $somecontent);fclose($handle);?> Quote Link to comment Share on other sites More sharing options...
rysio Posted January 15, 2007 Share Posted January 15, 2007 oh - would have forgotten this script is in one file with another script, which provides the value of $comment ...maybe this changes the thinking to it.... Quote Link to comment 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.