在项目列表中删除php中的文件
我有一个php脚本来显示计算机列表是否处于活动状态。每隔一分钟左右,它就会向我的服务器发送一个数据包,并更新一个文件 我编写的php脚本检查文件是否在最近90秒内更新。如果有,它将显示为活动,否则将显示为非活动在项目列表中删除php中的文件,php,Php,我有一个php脚本来显示计算机列表是否处于活动状态。每隔一分钟左右,它就会向我的服务器发送一个数据包,并更新一个文件 我编写的php脚本检查文件是否在最近90秒内更新。如果有,它将显示为活动,否则将显示为非活动 $thelist = ""; if ($handle = opendir('ips/')) { while (false !== ($file = readdir($handle))) { if (($file != ".") && ($file
$thelist = "";
if ($handle = opendir('ips/')) {
while (false !== ($file = readdir($handle))) {
if (($file != ".") && ($file != "..") && (substr($file, - 4) == ".ips")) {
$active = true;
$activetext = "<a class=activeGreen>● Active</a> ";
if(humanTiming(filemtime("ips/".$file)) > 90) {
$activetext = "<a class=inactiveRed>● Inactive</a> ";
$active = false;
}
if ($active == true) {
$thelist = $activetext.'<a>'.basename($file, ".ips")."</a> <a>[Delete]</a><br>".$thelist;
} else {
$thelist .= $activetext.'<a>'.basename($file, ".ips")."</a> <a>[Delete]</a><br>";
}
}
}
closedir($handle);
echo "<ul><p>$thelist</p></ul>";
}
function humanTiming($time) {
$time = time() - $time; // to get the time since that moment
$time = $time < 1 ? 1 : $time;
$tokens = [1 => 'second'];
foreach ($tokens as $unit => $text) {
if ($time < $unit) continue;
$numberOfUnits = floor($time / $unit);
return $numberOfUnits;
}
}
$thelist=”“;
如果($handle=opendir('ips/')){
while(false!=($file=readdir($handle))){
如果(($file!=“)&&($file!=“.”)和($file!=”)&&(substr($file,-4)=“.ips”)){
$active=true;
$activetext=”● 积极的”;
if(humantimeing(filemtime(“ips/”$file))>90){
$activetext=”● 不活跃”;
$active=false;
}
如果($active==true){
$thelist=$activetext.''.basename($file,.ips”)。“[Delete]
”$thelist;
}否则{
$thelist.=$activetext.''.basename($file,.ips”)。“[Delete]
”;
}
}
}
closedir($handle);
echo“$thelist”;
}
函数时间($time){
$time=time()-$time;//获取从该时刻开始的时间
$time=$time<1?1:$time;
$tokens=[1=>second'];
foreach($unit=>$text形式的令牌){
如果($时间<$单位)继续;
$numberOfUnits=楼层($time/$unit);
返回$numberOfUnits;
}
}
这一切都是可行的,但我如何才能让他们旁边的delete按钮在单击时删除该特定文件?我最后做的是创建第二个php文件,接受url get参数
<?php
if(!empty($_GET["fname"])) {
if(file_exists($_GET["fname"])) {
echo 'Deleting ' . htmlspecialchars($_GET["fname"]) . '!';
unlink($_GET["fname"]);
} else {
echo 'Error: ' . htmlspecialchars($_GET["fname"]) . ' does not exist';
}
} else {
echo 'Direct access not allowed';
}
?>