James
2012-06-09 23:40:34 UTC
PHP Error Message
Warning: file_get_contents(pathtoaexternalfile?format=xml) [function.file-get-contents]: failed to open stream: No such file or directory in /home/a5403572/public_html/archive/cron.php on line 14
Warning: file_put_contents(/archive/06.10.12.rss) [function.file-put-contents]: failed to open stream: No such file or directory in /home/a5403572/public_html/archive/cron.php on line 18
Warning: opendir(/archive/) [function.opendir]: failed to open dir: No such file or directory in /home/a5403572/public_html/archive/cron.php on line 26
Here is my Code.
//save current
$today = date("m.d.y");
$file = 'pathtoaexternalfile?format=xml';
// Open the file to get existing content
$current = file_get_contents($file);
// Write the contents back to the file
file_put_contents('/archive/'.$today.'.rss', $current);
// delete all files over x days
$days= 64 ;
$dir = '/archive/';
if ($handle = opendir($dir)) {
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
if ($file[0] == '.' || is_dir("$dir/$file")) {
// ignore hidden files and directories
continue;
}
if ((time() - filemtime($file)) > ($days *86400)) { //7 days
unlink("$dir/$file");
}
}
closedir($handle);
}
?>
Note: the file is called cron.php, Also the pathtoaexternalfile?format=xml is not actually pathtoaexternalfile?format=xml it is in the format http://www.website.com/dir/file?format=xml
Thanks in advance