I have a script like this, let's call this page select.php:
<?php
........
echo '
<form action="editor.php" method="post">
<select name="file">
<option value="volvo">Volvo.txt</option>
<option value="saab">Saab.txt</option>
<option value="mercedes">Mercedes.txt</option>
<option value="audi">Audi.txt</option>
</select>
<input type="submit" name="edit" value="Edit" />
</form>';
.........
?>
And I want to edit the selected file in another page called editor.php and then save it, how do I pass the value
of the selected file to editor.php and then edit it in a textarea
?
You can use PHP Open File - fopen().
<form action="editor.php" method="post">
<select name="file">
<option value="volvo">Volvo.txt</option>
<option value="saab">Saab.txt</option>
<option value="mercedes">Mercedes.txt</option>
<option value="audi">Audi.txt</option>
</select>
<textarea></textarea>
<input type="submit" name="edit" value="Edit" />
</form>
if(isset($_POST["edit"])) {
$filename = $_POST["file"];
$myfile = fopen("$filename", "r") or die("Unable to open file!");
$filecontent = fread($myfile,filesize("$filename"));
fclose($myfile);
}
<textarea>if(isset($filecontent)) { echo $filecontent; }</textarea> //echos file content in textarea.
//write to text file
if(isset($_POST["update"])) {
$myfile = fopen("$files", "w") or die("Unable to open file!");
fwrite($myfile, $_POST["textareaContent"]);
fclose($myfile);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다