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? Link to comment https://forums.phpfreaks.com/topic/81018-solved-store-the-output-of-a-php-script-instead-of-printing-it/ 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(); ?> Link to comment https://forums.phpfreaks.com/topic/81018-solved-store-the-output-of-a-php-script-instead-of-printing-it/#findComment-411022 Share on other sites More sharing options...
papaface Posted December 10, 2007 Author Share Posted December 10, 2007 Thanks Link to comment https://forums.phpfreaks.com/topic/81018-solved-store-the-output-of-a-php-script-instead-of-printing-it/#findComment-411046 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? Link to comment https://forums.phpfreaks.com/topic/81018-solved-store-the-output-of-a-php-script-instead-of-printing-it/#findComment-411414 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? Link to comment https://forums.phpfreaks.com/topic/81018-solved-store-the-output-of-a-php-script-instead-of-printing-it/#findComment-411421 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. Link to comment https://forums.phpfreaks.com/topic/81018-solved-store-the-output-of-a-php-script-instead-of-printing-it/#findComment-411426 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 Link to comment https://forums.phpfreaks.com/topic/81018-solved-store-the-output-of-a-php-script-instead-of-printing-it/#findComment-411435 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.