Monday, 15 March 2010

PHP file doesn't rewrite -



PHP file doesn't rewrite -

i create site map, , create php file, generate mysql. alter host , have problem writing file. can't understand something. here example:

<?php $xml = 'bla bla xml'; //... xml generating code $fp = fopen($_server['document_root'].'/my_site_map.xml', 'w'); if($fp) echo 'we opened it'; else echo 'we failed'; $fwrite=fwrite($fp, $xml, strlen($xml)); if($fwrite==false) echo "another fail"; fclose($fp); echo "we done"; ?>

the question is: file my_site_map.xml have permission 664 (rw-rw-r--), , can't utilize script if open php page browser, so, if seek i'll see: "we failed fail done"; if open through crontab , see log file, can see this: "we opened done". want main problem file isn't have been rewritten. why? , how can prepare this? thanks.

my server nginx not apache, didn't thought info valuable

well don't have plenty rep comment have answer.

i'm going take stab in dark , file owned user or root, not process running webserver. nor file owned grouping webserver process run under.

so either chown/chgrp file owned apache(?!) process running, e.g. chown apache file or set file have write permissions everyone, e.g. chmod 666 file

don't chmod 777 commented above unless it's executable file , want able run it. 1st solution improve practice giving read access file.

edit: in comment comments on original reply above, if file isn't executable don't give 7 permisions. 6 read/write , suitable text file opening write (even 2 if comes that).

edit 2: seek catching exceptions fopen function runs in seek grab block:

try { $fp = fopen($_server['document_root'].'/my_site_map.xml', 'w'); } grab (exception $e) { echo "the error is" . $e->getmessage(); }

php file permissions fopen

No comments:

Post a Comment