Remove feed files after import
Dear David,
Would it be possible to delete the feeds from the feeds folder after they have been imported into the database?
My feeds are automatically imported via this script:
<?php
function download($file_source, $file_target) {
$rh = fopen($file_source, 'rb');
$wh = fopen($file_target, 'wb');
if ($rh===false || $wh===false) {
// error reading or opening file
return true;
}
while (!feof($rh)) {
if (fwrite($wh, fread($rh, 1024)) === FALSE) {
// 'Download error: Cannot write to file ('.$file_target.')';
return true;
}
}
fclose($rh);
fclose($wh);
// No error
return false;
}
//AW feeds
download('http://********Type=2','****.xml');
download('http://********Type=2','****.xml');
download('http://********Type=2','****.xml');
header("Content-Type: text/plain");
passthru("php ../scripts/import.php @MODIFIED");
?>The feed files remain on the server, costing a lot of Megabytes, while they are useless after import...?
Best regards,
Al
Is it possible to erase those files automatically? The script above is activated once a day by a cron job. Is there a code to add, which removes the files once they are imported?
Hi Al,
Sure - try something like:
exec("rm -f ../feeds/*");(but make sure your fetch script isn't in /feeds/ of course!!)
Cheers,
David.
--
Developer, Price Tapestry
General PHP, MySQL and Affiliate Marketing tech help for Price Tapestry customers at davidmorison.com
Of course my fetch script is in that folder... :-P
So, will this modification work, to prevent the autoimport.php file from being erased?
exec("rm -f ../feeds/*.xml");Alternatively I can move the file to another folder and adjust the cron job, but then I don't know where the feeds will be loaded.
And can I safely insert this code in the last line of the fetch script above?
Hi Al,
Yes - using *.xml would work fine.
The alternative perhaps would be to keep your fetch script in /scripts/, and prefix each of the download filenames with "../feeds/"
Cheers,
David.
--
Developer, Price Tapestry
General PHP, MySQL and Affiliate Marketing tech help for Price Tapestry customers at davidmorison.com
Hello Al,
Yes - that's fine - the admin page will show the "De-Register" link alongside each filename, so as long as you don't click de-register it will be fine.
Cheers,
David.
--
Developer, Price Tapestry
General PHP, MySQL and Affiliate Marketing tech help for Price Tapestry customers at davidmorison.com