我已经想出了如何为每个帖子创建一个数组,以便txt文件是唯一的,但是我一直试图弄清楚如何删除它。这是我迄今取得的进展:如何使用php删除特定的txt文件
的index.php:
<?php
$fileNames = glob("*.txt");
$posts = array();
foreach($fileNames as $fileName) {
$post = file($fileName);
array_push($posts, $post);
}
$postNum = 0;
foreach($posts as $post) {
$i = 1;
$fname = $fileNames[$postNum];
foreach($post as $line) {
if ($i==1) {
echo "<h1 style=\"padding: 0px 30px 0px 30px;\">$line</h1>";
} else {
echo "<p style=\"padding: 0px 30px 0px 30px; color:#4d4d4d;\">$line</p>";
echo "<form action=\"deletepost.php\" method=\"get\" style=\"padding: 0px 30px 0px 30px;\"><input type=\"submit\" value=\"Delete Post\"><input type='hidden' name='filename' value='".$fname."'></form>";
}
$i++;
}
$postNum++;
}
?>
Deletepost.php:
<?php
session_start();
if($_SESSION['authenticated'] != true) {
header("Location: login.php");
die();
}
?>
我知道我必须使用$ _REQUEST [ '名'];在deletepost.php中的某处,但是就我所知而言。任何帮助表示赞赏。谢谢。
请参阅php unlink http://php.net/manual/en/function.unlink.php文档。 –