文本文件的简单PHP编辑器 [英] Simple PHP editor of text files

查看:303
本文介绍了文本文件的简单PHP编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为客户开发了一个站点,他希望能够在后端类型的解决方案中编辑主页的一小部分.因此,作为解决方案,我想添加一个非常基本的编辑器(domain.com/backend/editor.php),当您访问它时,它将具有一个带有代码和保存按钮的文本字段.它将要编辑的代码将设置为TXT文件.

I have developed a site for a client and he wants to be able to edit a small part of the main page in a backend type of solution. So as a solution, I want to add a very basic editor (domain.com/backend/editor.php) that when you visit it, it will have a textfield with the code and a save button. The code that it will edit will be set to a TXT file.

我认为这样的事情在PHP中很容易编写,但是google这次并没有为我提供帮助,因此我希望这里有人会为我指明正确的方向.请注意,我没有PHP编程的经验,只有HTML和基本的javascript,所以请在提供的任何答复中都做到周密.

I would presume that such thing would be easy to code in PHP but google didn't assist me this time so I am hoping that there might be someone here that would point me to the right direction. Note that I have no experience in PHP programming, only HTML and basic javascript so please be thorough in any reply that you provide.

推荐答案

您创建HTML表单来编辑文本文件的内容.如果提交了,则更新文本文件(并再次重定向到表单,以防止出现F5/刷新警告):

You create a HTML form to edit the text-file's content. In case it get's submitted, you update the text-file (and redirect to the form again to prevent F5/Refresh warnings):

<?php

// configuration
$url = 'http://example.com/backend/editor.php';
$file = '/path/to/txt/file';

// check if form has been submitted
if (isset($_POST['text']))
{
    // save the text contents
    file_put_contents($file, $_POST['text']);

    // redirect to form again
    header(sprintf('Location: %s', $url));
    printf('<a href="%s">Moved</a>.', htmlspecialchars($url));
    exit();
}

// read the textfile
$text = file_get_contents($file);

?>
<!-- HTML form -->
<form action="" method="post">
<textarea name="text"><?php echo htmlspecialchars($text) ?></textarea>
<input type="submit" />
<input type="reset" />
</form>

这篇关于文本文件的简单PHP编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆