我有以下的php文件,它执行cron作业。如何添加一旦完成的功能,目录中的xml文件就会被删除。PHP脚本完成后删除文件
<?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);
}
}
?>
非常感谢您的帮助!非常感激。
添加在脚本底部的[取消链接()的调用](http://www.php.net/manual/en/function.unlink.php) – Tularis
使用取消链接? http://www.php.net/manual/en/function.unlink.php – briosheje