开发者

Can't add contents to file using file_put_contents

开发者 https://www.devze.com 2022-12-08 10:57 出处:网络
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

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_c开发者_StackOverflow中文版ontents($dir.'/contact.php',$content); is does not?


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);


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

0

精彩评论

暂无评论...
验证码 换一张
取 消