May 2021 3 245 Report
PHP help? Syntax issue - i think?

Hi, I was just wondering where i have made a mistake with my code. I am trying to save a file with the current date to a folder, than delete all files in that folder that are over 64days old. Currently I get these errors.

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.

<?php

//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

Update:

Update: thanks for your reply, but what do i do if it is an external file

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Copyright © 2024 VQUIX.COM - All rights reserved.