papaface Posted December 10, 2007 Share Posted December 10, 2007 Hello, Is it possible to have a php file process, BUT instead of sending it to the browser, make it create a new file with the output of the first script as its source code? Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 <?php ob_start(); include 'filetoexecute.php'; // note: you can also simply put your code to be executed in here. file_put_contents('output.txt',ob_get_contents()); ob_end_clean(); ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted December 10, 2007 Author Share Posted December 10, 2007 Thanks Quote Link to comment Share on other sites More sharing options...
papaface Posted December 10, 2007 Author Share Posted December 10, 2007 hmm this doesnt work with PHP4 so I did: ob_start(); include('templates/header.tpl'); include ('templates/generators/index_main.tpl'); // note: you can also simply put your code to be executed in here. include('templates/footer.tpl'); $File = 'templates/cached/index.html'; $fh = fopen($File, 'w+') or die("can't open file"); fwrite($fh, ob_get_contents()); fclose($fh); ob_end_clean(); But it is producing empty files. But when I do it with the file_put_contents() method it works. Why? Quote Link to comment Share on other sites More sharing options...
trq Posted December 10, 2007 Share Posted December 10, 2007 I don't see an issue here. What does.... <?php ob_start(); include('templates/header.tpl'); include ('templates/generators/index_main.tpl'); // note: you can also simply put your code to be executed in here. include('templates/footer.tpl'); //$File = 'templates/cached/index.html'; //$fh = fopen($File, 'w+') or die("can't open file"); //fwrite($fh, ob_get_contents()); //fclose($fh); echo ob_get_contents(); ob_end_clean(); ?> produce? Quote Link to comment Share on other sites More sharing options...
papaface Posted December 10, 2007 Author Share Posted December 10, 2007 Nothing is displayed. In the code I had before it displays the page I am trying to write to a new file. P.S The server is a Plesk server if that matters. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 10, 2007 Author Share Posted December 10, 2007 Ah its working now, it was a simple folder permissions problem lol. Thanks anyway 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.