How to edit selected file in a dropdown list in textarea and then save it?

Fred

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?

user254153

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How do I print a list of what has been selected in an Excel dropdown list?

분류에서Dev

Ruby On Rails-Forms For Select Dropdown Selected 옵션 on Edit

분류에서Dev

DropDown list doesnt update selected value

분류에서Dev

How to save or edit javascript files in ace editor

분류에서Dev

Unicode elements in list save to file

분류에서Dev

How can I change the output of a label, based on what's selected from a dropdown list (C# in ASP.NET)

분류에서Dev

How to edit file system of partition?

분류에서Dev

How do I edit a file and preserve its access control list / SELinux security context?

분류에서Dev

Save html textarea state

분류에서Dev

How to show a dropdown menu filter selected value after form is submitted?

분류에서Dev

How to get the last value selected from dropdown and disable it using jquery

분류에서Dev

How to get selected value of dropdown when using partial view in mvc?

분류에서Dev

How to display the selected value from the dropdown menu using JQuery?

분류에서Dev

how to save belongsToMany for edit action in CakePHP 3.x?

분류에서Dev

How to save the JS output to a file

분류에서Dev

How to save file and corresponding url?

분류에서Dev

How to import, export and edit bookmarks of a pdf file?

분류에서Dev

How to permanently edit the core_pattern file?

분류에서Dev

Pandas: how to edit values in a column of a .csv file?

분류에서Dev

Dropdown selected with URL parameter

분류에서Dev

how to output a bootstrap dropdown list on two columns?

분류에서Dev

Photoshop: How to save selection so I know location of selected pixels

분류에서Dev

If statement confusion - how to display a div if file is selected

분류에서Dev

How to print selected elements from file?

분류에서Dev

Read Excel file using PHPExcel in Symfony2, edit contents of one cell then save to database

분류에서Dev

How can I save the last command to a file?

분류에서Dev

How to save a rotated Adobe PDF file

분류에서Dev

How to save results of a SQL query to html file?

분류에서Dev

How to split file and save parts to multiple locations?

Related 관련 기사

  1. 1

    How do I print a list of what has been selected in an Excel dropdown list?

  2. 2

    Ruby On Rails-Forms For Select Dropdown Selected 옵션 on Edit

  3. 3

    DropDown list doesnt update selected value

  4. 4

    How to save or edit javascript files in ace editor

  5. 5

    Unicode elements in list save to file

  6. 6

    How can I change the output of a label, based on what's selected from a dropdown list (C# in ASP.NET)

  7. 7

    How to edit file system of partition?

  8. 8

    How do I edit a file and preserve its access control list / SELinux security context?

  9. 9

    Save html textarea state

  10. 10

    How to show a dropdown menu filter selected value after form is submitted?

  11. 11

    How to get the last value selected from dropdown and disable it using jquery

  12. 12

    How to get selected value of dropdown when using partial view in mvc?

  13. 13

    How to display the selected value from the dropdown menu using JQuery?

  14. 14

    how to save belongsToMany for edit action in CakePHP 3.x?

  15. 15

    How to save the JS output to a file

  16. 16

    How to save file and corresponding url?

  17. 17

    How to import, export and edit bookmarks of a pdf file?

  18. 18

    How to permanently edit the core_pattern file?

  19. 19

    Pandas: how to edit values in a column of a .csv file?

  20. 20

    Dropdown selected with URL parameter

  21. 21

    how to output a bootstrap dropdown list on two columns?

  22. 22

    Photoshop: How to save selection so I know location of selected pixels

  23. 23

    If statement confusion - how to display a div if file is selected

  24. 24

    How to print selected elements from file?

  25. 25

    Read Excel file using PHPExcel in Symfony2, edit contents of one cell then save to database

  26. 26

    How can I save the last command to a file?

  27. 27

    How to save a rotated Adobe PDF file

  28. 28

    How to save results of a SQL query to html file?

  29. 29

    How to split file and save parts to multiple locations?

뜨겁다태그

보관