PHP寫入、讀出、表單更改檔案內容顯示!(原生態)
阿新 • • 發佈:2018-12-12
直接上程式碼:
一、寫入和顯示已寫入檔案內容:
<?php header("Content-type: text/html; charset=utf-8"); $name = "無"; // echo "\n開始\n"; // var_dump($_GET); //首先看是否傳值過來了,如果有就寫入檔案 if($_POST['name']&&$_POST['type']){ $name = $_POST['name']; $myfile = fopen("./wxm.txt", "w") or die("Unable to open file!!W"); fwrite($myfile, $name); fclose($myfile); } $type = time(); $myfile = fopen("./wxm.txt", "r") or die("Unable to open file!!R"); $name = fread($myfile, filesize("./wxm.txt")); fclose($myfile); // 直接展示當前的數值,可提供提交的form表單 echo "<form action=\"./qiang.php\" method=\"post\" class=\"form-horizontal\" enctype=\"multipart/form-data\"> <label><span style=\"color: red;\">*</span>請輸入當前公眾號名字:</label> <input type=\"hidden\" name='type' value=\"".$type."\"> <input type=\"text\" name='name' value=\"".$name."\" placeholder=\"請輸入公眾號名字\"> <button type=\"submit\" class=\"btn btn-primary\">提交設定</button> </form>";