index.php를PHP 텍스트 편집기
<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의 $ file 변수는 텍스트 파일의 경로입니다. 일단 클릭하면 링크의 텍스트와 경로를 동일하게 만드는 방법은 무엇입니까? 일단 텍스트 파일 링크를 클릭하면 편집기에서 열리는 것이 좋습니다. 도움이된다면 고맙겠습니다. 감사합니다.
어떤 쿼리 문자열에 넣어 어떻습니까? GET 매개 변수로 보내는 것이 가장 쉬운 방법입니다. ('echo "".$file."";'). 우선이 절차에서 보안 문제를 고려할 것입니다. – jtheman
보안에 대한 실질적인 걱정은 없습니다. 이 코드는 대학 과제를위한 것입니다. 필자 자신에게는 PHP가 처음이다. 도와 주셔서 감사합니다. – ech0