ScrewLooseSalad Posted December 18, 2012 Share Posted December 18, 2012 I'm still a little bit new to PHP, and I want to ammend the beginning of a text file, moving the previous content toward the end; reading around online the conensus I seem to be finding is that this is not possible with the functions as they are, so I plan to move the conents of a first 'master' file to a second 'hold' file, so I can then ammend the master file with the conents of the hold file afterward; however I'm not sure if it is possible to open two files at once; using some sample code I found online I hashed together this piece of code: /*******************/ /* WRITE TO FILE */ /*******************/ /*pass master news file to the hold file*/ flock($fq, LOCK_EX); //lock file fseek($fq,0); fwrite($fq, $fp, strlen($fp)); flock($fq, LOCK_UN); //unlock file fclose($fq); /*generate new news code*/ $date = date('jS F Y'); $outputstring = "<p><em class="newsheader">".$header."</em> - ".$date."\t"."<br>".$newsbody."</p><br>"; flock($fp, LOCK_EX); //lock file fseek($fp,0); fwrite($fp, $outputstring, strlen($outputstring)); flock($fp, LOCK_UN); //unlock file fclose($fp); echo '<p>News write successful</p>'; The master file is replaced fine, however, the hold file ends up containing "Resource id #1", is it not possible to hold open two files at once? Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.