的index.phpPHP文本编辑器
<h1>View text files in a directory</h1>
<form action="" method="POST">
Directory name: <input name="folderName4" type="text" required="required"> <br>
<input type="submit" value="View Directories Text Files">
</form>
<br>
<?php
if (isset($_POST['folderName4'])){
$foldername = $_POST["folderName4"];
$directory = "upload"."/".$foldername."/";;
$files = glob($directory . "*.txt");
foreach($files as $file)
{
echo "<a href=edit.php>".$file."</a>";
echo "<br>";
}
}
?>
edit.php
<?php
$url = 'http://127.0.0.1/ccb/edit.php';
$file = ;
if (isset($_POST['text']))
{
file_put_contents($file, $_POST['text']);
// redirect to the form, avoids refresh warnings from the browser
header(sprintf('Location: %s', $url));
printf('<a href="%s">Moved</a>.', htmlspecialchars($url));
exit();
}
$text = file_get_contents($file);
?>
<form action="" method="post">
<textarea name="text"><?php echo htmlspecialchars($text) ?></textarea>
<input type="submit">
</form>
好了,所以index.php文件列出的目录中的链接和edit.php编辑文本文件中的所有文本文件。 edit.php中的$ file变量是文本文件的路径,我将如何使路径与链接中的文本一旦被点击相同?这个想法是,一旦文本文件链接被点击,它将在编辑器中打开。任何帮助将不胜感激,谢谢。
怎么样把它的查询字符串?将它作为GET参数发送将是最简单的方法。 ('echo“".$file."”;')。首先我会考虑这个过程中的安全问题。 – jtheman
没有真正担心安全。该代码是为大学任务。我自己对PHP很陌生。谢谢您的帮助。 – ech0