lpet Posted May 13, 2007 Posted May 13, 2007 Maybe I'm missing something simple (usually the case). I've searched through the forums and found similar problems, but not quite the same as mine. I am trying to write to a file (datafile.xml) using PHP in myfile.php. Here is my code: >$filetoopen=$_SERVER["DOCUMENT_ROOT"]."/travel/data/datafile.xml"; if ($fp = fopen($filetoopen,"r+") !== false) { $newcode.='<p>Blah blah blah. Test text here.</p>'; fseek ($fp,-16,SEEK_END); //go to the end of the file, and back up 17 bits if (fwrite($fp,$newcode,700)!==false) echo 'Success'; else echo 'Error'; fclose($fp); } fopen seems to work fine. The errors I'm getting are: Warning: fseek(): supplied argument is not a valid stream resource in /home/myusername/public_html/travel/myfile.php on line 43 Warning: fwrite(): supplied argument is not a valid stream resource in /home/myusername/public_html/travel/for_us/myfile.php on line 46 Warning: fclose(): supplied argument is not a valid stream resource in /home/myusername/public_html/travel/for_us/myfile.php on line 54 I have even tried is_readable and is_writeable using $filetoopen and they are both true. I have tried other things such as fgets and get the same error. Permissions on datafile.xml are 666, and the directory 'data' is set to 777. I'm not sure what else to try. Thanks in advance for any help you can give. I'm so frustrated with this. ~LPet Quote
TCH-Andy Posted May 13, 2007 Posted May 13, 2007 Welcome to the forums lpet Try; >$filetoopen=$_SERVER["DOCUMENT_ROOT"]."/travel/data/datafile.xml"; $fp = fopen($filetoopen,"r+"); if ($fp !== false) { $newcode.='<p>Blah blah blah. Test text here.</p>'; fseek ($fp,-16,SEEK_END); //go to the end of the file, and back up 17 bits if (fwrite($fp,$newcode,700)!==false) echo 'Success'; else echo 'Error'; fclose($fp); } Quote
lpet Posted May 14, 2007 Author Posted May 14, 2007 Try; >$filetoopen=$_SERVER["DOCUMENT_ROOT"]."/travel/data/datafile.xml"; $fp = fopen($filetoopen,"r+"); if ($fp !== false) { Brilliant! Thank you so much, worked like a charm. It's simple but I don't know if I would have ever figured that one out. Learning every day. Sigh of relief. Quote
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.