Hi!
I'd like to know if there's a way to save a webpage address, as HTML (like the browser displays it) and store it under a folder. What I want to do for my website is to create some sort of cache image of the index page, available for me to read in browser. This image, for example example.com/index.html, must be stored using different names, if possible using the date: example.com/index.html will be stored today as example.com/cache/index-today-date.html.
Also, it would be even better, I suppose, if folder would be created, for each month or week. Ex. example.com/cache/January/index-today-date.html.

Any suggestion would be good. I'm thimking maybe a simple script, runned by a cronjob, daily, but couldn't find any.
Thank you!

OK. So far I've been able to get this to run as a cron:

<?php
$mypath="/home/example/public_html/cache";
mkdir($mypath,0777,TRUE);
$filename = $mypath.'/cache.html';
$handle = fopen($filename,"x+");
$homepage = file_get_contents('http://example.com');
fwrite($handle,$homepage);
echo "Success";
fclose($handle);
?>

But, how can I make it save the cache-date.html instead of cache.html?

Any ideas? I have advanced a little, now I have:

<?php
$mypath="/home/example/public_html/cache";
mkdir($mypath,0777,TRUE);
$today = date("m.d.y");
$filename = $mypath.'/cache-'.$today.'.html';
$handle = fopen($filename,"x+");
$homepage = file_get_contents('http://example.com');
fwrite($handle,$homepage);
echo "Success";
fclose($handle);
?>

When I run it it displays the Success message, but no page is written in the cache folder.

I must corect myself - the code above works, I was looking in other folder for the cache files :)

This article has been dead for over six months. Start a new discussion instead.