![](/img/trans.png)
[英]How to save the value of a textbox to a .txt file using php in html without reloading or redirecting the page?
[英]How to save file txt using html and php
我嘗試將 html 中的 textarea 保存到文件(“C:\xampp\htdocs\test\1\one.txt”)
所以我想我也必須使用 php。
這個 php 代碼,它工作正常
$fp = fopen('one.txt', 'w');
fwrite($fp, 'edit me please');
fclose($fp);
?>
那么我如何使用 html textarea 來編輯 php '請編輯我'到我想編輯的任何文本,另外,如果我需要,我想啟用多行保存在 one.txt 中。
我的 html 代碼
<!DOCTYPE html>
<html>
<head>
<title>Using innerHTML</title>
</head>
<body>
your one.txt write in textarea :
<br>
<textarea id="emp" rows = "20" cols = "90" name = "description"></textarea>
<br>
<p>
<input type="button" id="bt" value="Change Label Text" onclick="Onclicky()" />
</p>
</body>
<script language="javascript">
function Onclicky() {
/////function which will do work, idk?!////
}
</script>
</html>
更新#1(嘗試在 html 中添加 php),但仍然無法工作,沒有創建 txt 文件數據。)
<html>
<body>
<form action="" method="post">
<textarea name="text"></textarea>
<input type="submit" value="edit" />
</form>
<?php
if(isset($_POST["text"]){
$fp = fopen('one.txt', 'w');
if(fwrite($fp, $_POST["text"])){
echo "Edited";
}
fclose($fp);
}
?>
</body>
</html>
我還是新手,很高興為您提供幫助:)..
您需要了解有關“使用 PHP 處理表單”的更多信息。
html:
<form action="your_data.php" method="get">
Enter a Name:
<br>
<textarea id="emp" rows = "20" cols = "90" name = "name"></textarea>
<br>
<input type="submit">
</form>
</body>
</html>
your_data.php:
<html>
<body>
your data :
<?php
$fp = fopen('one.txt', 'w');
fwrite($fp, $_GET["name"]);
fclose($fp);
?>
</body>
</html>
這是最簡單的方法。
<form action="" method="post">
<textarea name="text"></textarea>
<input type="submit" value="edit" />
</form>
<?php
if(isset($_POST["text"]){
$fp = fopen('one.txt', 'w');
if(fwrite($fp, $_POST["text"])){
echo "Edited";
}
fclose($fp);
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.