He buscado durante bastante tiempo, para ver si es posible "agregar" a un archivo si se usa ob_start con PHP.Cómo anexar al archivo usando ob_start
He intentado lo siguiente pero no funcionó. ¿Alguna forma de lograr esto?
<?php
$cacheFile = 'file.txt';
if ((file_exists($cacheFile)) && ((fileatime($cacheFile) + 600) > time()))
{
$content = file_get_contents($cacheFile);
echo $content;
} else
{
ob_start();
// write content
echo '<h1>Hello world</h1>';
$content = ob_get_contents();
ob_end_clean();
file_put_contents($cacheFile,$content,'a+'); // I added the a+
echo $content;
}
?>
Pedí prestado el ejemplo anterior de otra publicación en S.O.
'file_put_contents' realmente admite el archivo adjunto :) –
@Jack: Realmente no sabía eso :-P ¡Ahora sí! Dejaré esto aquí de todos modos. –
Gracias Rocket, funcionó maravillosamente. Saludos ~ –