我有这个简单的网页内容编辑器。PHP内容:删除数据
<?php
if (isset($_POST['edit'])) {
if (file_put_contents('homecontent.txt', $_POST['homecontent']) !== FALSE)
echo '<p class="success">Home Content Saved Successfully!</p>', "\n";
}
$homecontent = file_get_contents('homecontent.txt');
if (isset($_POST['header'])) {
if (file_put_contents('headercontent.txt', $_POST['headercontent']) !== FALSE)
echo '<p class="success">Header Content Saved Successfully!</p>', "\n";
}
$headercontent = file_get_contents('headercontent.txt');
if (isset($_POST['cssfile'])) {
if (file_put_contents('style.css', $_POST['cssfile']) !== FALSE)
echo '<p class="success>Style.css Saved Successfully!</p>', "\n";
}
$cssfile = file_get_contents('style.css');
?>
<div id="forms">
<form method="post" action="">
<p>Here you can edit your homepage text:</p>
<textarea name="homecontent" id="homecontent" rows="20"><?php echo $homecontent?></textarea>
<p><buton type="submit" name="edit">Save changes</button></p>
</form>
<form method="post" action="">
<p>Here you can edit your header content:</p>
<textarea name="headercontent" id="headercontent" rows="10"><?php echo $headercontent?></textarea>
<p><button type="submit" name="header">Save changes</button></p>
</form> </div>
<form method="post" action="">
<p>Here you can edit style.css file:</p>
<textarea name="cssfile" id="cssfile" rows="10"><?php echo $css?></textarea>
<p><button type="submit" name="cssfile">Save changes</button></p>
</form>
这个脚本中的问题是第三个表单动作没有得到执行。我得到成功消息,但style.css文件没有写入&它也删除任何现有的内容。前2个表单动作完美无缺。
因为其他2文件正在工作,所以不能是目录权限错误。
$ _POST ['cssfile']中的某些示例内容是什么?作为一个测试,试试file_put_contents('style.css','hello world')!== FALSE ...如果这样的话,你知道这个问题与$ _POST ['cssfile'] –
错误变量的内容有关。错误报告会告诉你。另外,一个错字'
我也看到了错字,但假定它在原始源代码中没问题,因为否则就没有提交按钮会立即启动。 – syck