php url http web archive org web 20160404232801 http fc-dmitrov ru fil

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
$url = 'http://web.archive.org/web/20160404232801/http://fc-dmitrov.ru/';
$f = file_get_contents($url);
$domain = $_SERVER['HTTP_HOST'];
preg_match_all('|src="([^"]+)"|', $f, $m); //for all src (inc scripts, images)
foreach ($m[1] as $l){
if (strpos($l, $domain)!=FALSE)
{
$tmp = explode($domain,$l); //split string WA_part -> domain_part
$path = explode('/',$tmp[1]); //split domain part to path
$num = count($path);
$cpath = ''; //no path before checking
for ($i=0;$i<$num-1;$i++)
$cpath .= $path[$i].' ';
$cpath = str_replace(' ','/',trim($cpath));
@$tfile = file_get_contents('http://web.archive.org/'.$l); //404 may appear
if (!file_exists($cpath.'/'.$path[$num-1])){ //if there's not such a file
$out = file_put_contents($cpath.'/'.$path[$num-1], $tfile);
echo $out.' '.$cpath.'/'.$path[$num-1].'OK <br/>';
}
else echo 'File found<br/>';
}
}