我有這個簡單的網頁內容編輯器。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