메모장 써서 텍스트 화일 저장시, 수정시 수정할 글이 보이게 하기

Programming/PHP 2010. 10. 21. 10:38

<?
if($_POST['Submit']){  // Submit 이라는 인풋이 만약에 있으면
$open = fopen("textfile.txt","w+"); // textfile.txt 라는 텍스트 화일을 overwritten + 포인터 제일 처음에 놓고 오픈해서
$text = $_POST['update']; // $text 라는 변수에 textarea 의 글들을 저장후
fwrite($open, $text); // 연 텍스트 화일에다가 집어넣어뿌고
fclose($open); // 닫아불겨
echo "File updated.<br />"; // 글구 업데이트되었당께~ 라고 알려주세
echo "File:<br />";
$file = file("textfile.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{ // 만약 서브밋 버튼 안 누지르고 그냥 이 페이지가 열린 상태라면
$file = file("textfile.txt");  // 일단 textfile.txt 화일 열어서 textarea에 뿌려주불랑께
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>


source code from
Pixelcode

http://www.dynamicdrive.com/forums/archive/index.php/t-4539.html