tags:

views:

65

answers:

2

I'm outputting the contents of a file to another file, but the contents is just not being put into the second file. It creates the file but does not put the output to the file, it displays the output on the screen.

require_once 'templates/'.$layout.'/contact.php';
ob_start();
$content = ob_get_clean();

file_put_contents($dir.'/contact.php',$content);
chmod($dir.'/contact.php',0777);

The funny thing is when I do this file_put_contents($dir.'/contact.php','dsf'); it writes to the file, when doing file_put_contents($dir.'/contact.php',$content); is does not?

A: 

you might not have the rights to write to that file, or folder if you are creating that file

solomongaby
-rwxrwxrwx 1 www-data www-data 0 2009-10-07 17:20 contact.phpdrwxr-xr-x 2 www-data www-data 4096 2009-10-07 17:19 8c492a19cfbb713f89d0946482c5ee42
Roland
+3  A: 

I don't understand... You include a file and then call ob_start() followed by an immediate ob_get_clean().

What is suppose to be in the ob_get_clean??

You should have:

ob_start(); //<--- Start the buffer

require_once 'templates/'.$layout.'/contact.php';

$content = ob_get_clean();

file_put_contents($dir.'/contact.php',$content);
chmod($dir.'/contact.php',0777);
AntonioCS
@Roland - this should be marked as the correct answer.
karim79
@Roland - thanks, @Antonio - voted up.
karim79
fixed it, thx Antonio
Roland
@karim79: Nice gesture!
Ferdinand Beyer