I have the following php file which executes with a cron job. How can I add the functionality that once completed, the xml files in the directory get deleted.
<?php
// Create connection
$con=mysqli_connect("localhost","test","test","epg");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$dir = "xml-files/";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (($file !== '.') && ($file !== '..') ) {
$doc = simplexml_load_file($dir . $file);
foreach ( $doc->ScheduleData->ChannelPeriod as $channelPeriod )
{
$channelId = $channelPeriod->ChannelId;
foreach ( $channelPeriod->Event as $event )
{
$beginTime = $event['beginTime'];
$duration = $event['duration'];
$programName = $event->EpgProduction->EpgText->Name;
$description = $event->EpgProduction->EpgText->Description;
$EventId = $event->EventId;
$sql = "insert into `epg` (`EventId`,`ChannelId`, `BeginTime`,`Duration`, `ShortName`, `Description`) values ('$EventId','$channelId', '$beginTime','$duration', '$programName', '$description')";
if (mysqli_query($con,$sql))
{
echo "Database updated successfully";
}
else
{
echo "Error creating database: " . mysqli_error($con);
}
}
}
}
}
closedir($dh);
}
}
?>
Many thanks for your help guys! much appreciated.