Javascript 如何将wysisyg内联编辑器中的内容保存到.php文件
我找到了一个“”,我让它在本地主机(Ubuntu 14.04)上运行 其目的是,将其嵌入我的网站,并将其用作我网站的主要写作工具。我需要能够选择文件名,或者让它在文件名的空白处添加Javascript 如何将wysisyg内联编辑器中的内容保存到.php文件,javascript,php,html,editor,inline,Javascript,Php,Html,Editor,Inline,我找到了一个“”,我让它在本地主机(Ubuntu 14.04)上运行 其目的是,将其嵌入我的网站,并将其用作我网站的主要写作工具。我需要能够选择文件名,或者让它在文件名的空白处添加- 这是我写在上面用来保存内容的代码 () inline.php <form action="effe.php" method="post"> <input type="text" name="author" value="" placeholder="Author">
-
这是我写在上面用来保存内容的代码
()
inline.php
<form action="effe.php" method="post">
<input type="text" name="author" value="" placeholder="Author">
<input type="text" name="header" value="" placeholder="header">
<input type="datetime" name="datetime" value="" placeholder="datetime">
<div id='editor' contenteditable contextmenu="mymenu" name='editor'>
<p>This is just some example text to start us off</p>
</div>
<div class="tags">
<input type="text" name="" value="" placeholder="tag">
<input type="text" name="" value="" placeholder="tag">
<input type="text" name="" value="" placeholder="tag">
</div>
<input type="submit" value="Submit">
</form>
这只是一些示例文本,让我们开始
save.php
<?php
if (!empty($_POST))
{
foreach ( $_POST as $key => $value )
{
if ( ( !is_string($value) && !is_numeric($value) ) || !is_string($key) )
continue;
?>
<?php echo htmlspecialchars( (string)$key ); ?>
<div class="article-meta">
<a class="author" rel="author" title="author" href="/about" target="_blank"><?php echo "$author";?></a>
<time datetime="<?php echo "$datetime";?>" title="<?php echo "$datetime";?>"><?php echo "$datetime";?></time>
</div>
<h1><?php echo "$header"; ?></h1>
<?php echo "$editor"; ?>
<div class="tags">
<span> <?php echo "$tag1"; ?> </span>
<span> <?php echo "$tag2"; ?> </span>
<span> <?php echo "$tag3"; ?> </span>
</div>
<?php
}
}
?>
我不是100%确定你是什么;我们正在努力完成。我是你提到的那篇文章的作者,我很乐意帮忙
我不确定你的方法;我们尝试使用的是实用的。这里最好的选择是建立一个数据库并将内容写入其中
使用php非常简单,我建议看一看PDO,数据库抽象层。还有一些其他的,但是这一个为你做了一些关于注射攻击等的工作,所以这是一个很好的起点
听起来您需要一个相当简单的数据库表,很可能是:
create table articles (
article_id INT NOT NULL AUTO INCREMENT,
title VARCHAR(100) NOT NULL,
content TEXT NOT NULL,
article_date DATE
PRIMARY KEY (tutorial_id)
);
$dbh = new PDO('mysql:host=localhost;dbname=articles', 'user', 'pwd');
$sth = $dbh->prepare('INSERT INTO articles (title, content, article_date) values (:title, :content, NOW())');
$sth->bindParam(':title', $_POST['title']);
$sth->bindParam(':content', $_POST['content']);
$sth->execute();
从编辑器表单发回数据时,可以执行以下操作:
create table articles (
article_id INT NOT NULL AUTO INCREMENT,
title VARCHAR(100) NOT NULL,
content TEXT NOT NULL,
article_date DATE
PRIMARY KEY (tutorial_id)
);
$dbh = new PDO('mysql:host=localhost;dbname=articles', 'user', 'pwd');
$sth = $dbh->prepare('INSERT INTO articles (title, content, article_date) values (:title, :content, NOW())');
$sth->bindParam(':title', $_POST['title']);
$sth->bindParam(':content', $_POST['content']);
$sth->execute();
要将其从数据库中回调,请使用以下方法:
$dbh=newpdo('mysql:host=localhost;dbname=articles','user','pwd');
$sth=$dbh->query('SELECT*FROM articles')
还有比这更重要的一点,例如,您希望添加一个try/catch块以避免错误,您可能希望选择一个特定的文章(即,从article_id=45的文章中选择*),但我希望这将为您指明正确的方向
我认为试图避免使用数据库会导致大量额外的工作,一旦你开始使用像MySQL这样的东西,你将很快启动并运行 因此,请保存@blade19899的内容对不起,我重新阅读了问题并更新了我的答案,因为我觉得我原来的答案根本不正确。希望我添加的答案更完整,对您更有帮助。如果您需要更多帮助,请随时直接联系:)很抱歉回复太晚(工作、考试、女性)。我没有那么多文章,所以现在-正如我在a中所述-我想将编辑器中的内容保存在a.php
中。我将在将来研究数据库。这是可以做到的,但让您的web服务器能够写入web根目录并不是很好的做法。。。。攻击者可能会在服务器上写入恶意文件,从而危害服务器……这只是出于教育目的!此外,我没有一个引人注目的网站。