从网站管理面板编辑PHP、HTML文件
有没有办法让管理员能够编辑php和html文件 我知道有这种方法,但它会创建文件从网站管理面板编辑PHP、HTML文件,php,Php,有没有办法让管理员能够编辑php和html文件 我知道有这种方法,但它会创建文件 <?php $myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); $txt = "John Doe\n"; fwrite($myfile, $txt); $txt = "Jane Doe\n"; fwrite($myfile, $txt); fclose($myfile);
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
我试图让它成为管理员可以从管理面板编辑文件的地方,就像Wordpress在管理面板中可以查看和编辑文件的地方。我有办法做到这一点吗?我已经有了一个管理面板,但我无法找到它。有什么想法吗 你能行。我告诉你,你怎么能做到这一点。 看看这两个php文件。这是最简单的方法 编辑_file.php
<?php
$file = "1.html"; // file to edit
$html = file_get_contents($file); //read the file contents
$html = htmlentities($html, ENT_QUOTES);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit File</title>
<script>
function encode_content(){
var content = document.getElementById('file_content').value;
document.getElementById('file_content').value = encodeURIComponent(content);
}
</script>
</head>
<body>
<form name="edit_form" method="post" action="save_file.php" onsubmit="encode_content()">
<textarea name="file_content" id="file_content" style="width:100%;" rows="20"><?php echo $html; ?></textarea>
<input type="submit" value="Save this file">
</form>
</body>
</html>
编辑文件
函数encode_content(){
var content=document.getElementById(“文件内容”).value;
document.getElementById('file_content')。value=encodeURIComponent(content);
}
save_file.php
<?php
$file_content = urldecode($_POST['file_content']);
file_put_contents('1.html', html_entity_decode($file_content)); //save the file
?>
您可以使用php读写文件,也可以在页面上显示内容并从表单提交内容。所以-是的,祝你好运。Wordpress使用的是数据库记录,而不是文件。大多数这样做的地方都使用DBs,而不是文件。@user3783243 Wordpress允许您在管理员中编辑主题文件(PHP、CSS等)。我想这就是OP的目的。