Save website sourecode to file via php

Chriswede picture Chriswede · Mar 17, 2012 · Viewed 12k times · Source

Hi I wan to save the sourecode of http://stats.pingdom.com/w984f0uw0rey to some directory in my website

<?php
if(!copy("http://stats.pingdom.com/w984f0uw0rey", "stats.html"))
{
echo("failed to copy file");
}
;
?>

but this does not work either for me:

<?php
$homepage = file_get_contents('http://stats.pingdom.com/w984f0uw0rey');
echo $homepage;
?>

But I cannot figure how to do it!

thanks

Answer

Sorin Buturugeanu picture Sorin Buturugeanu · Mar 17, 2012

use

<?

file_put_contents('w984f0uw0rey.html', file_get_contents('http://stats.pingdom.com/w984f0uw0rey'));

?>

be sure that the script has write privileges to the current directory