这是我的 news.php 文件:
<form action="create_file.php" method="post" class="form-horizontal"/>
<label class="control-label">Заглавие:</label>
<div class="controls">
<input name="name" type="text" width="40" class="span6 m-wrap" />
<input type="submit" value="Продължи..." class="btn red"></input>
</div>
</form>
这是我的 create_file.php
<?php
$pre_file_name = $_POST['name'];
$ext = ".txt";
$file_name = $pre_file_name.$ext;
fopen($file_name,'w');
?>
<form action="edit_file.php" method="post" class="form-horizontal"/>
<label class="control-label">Въведете новината (текст):</label>
<div class="controls">
<span class="field"><textarea class="span6 m-wrap" name="edit" cols="1600" rows="10"></textarea></span><p>
<input type="hidden" name="file_name" value="<?php echo $file_name; ?>">
<input class="btn red" type="submit" value="Създай!">
</div>
</form>
这是我的edit_file.php:
<?php
$edit = $_POST['edit'];
$file_name = $_POST['file_name'];
$file = fopen($file_name, 'w');
fwrite($file,$edit);
fclose($file);
header("Location: news-success.php");
?>
删除.php
<?php
$file = $_GET['name'];
unlink($file);
header('Location: news-delok.php');
?>
编辑.php
<?php
$file_name = $_GET['name'];
$file_read = fopen($file_name,"r");
$contents = fread($file_read, filesize($file_name));
fclose($file_read);
?>
<html>
<form action="edit_file.php" method="POST">
<label>Title:</label>
<input class="span6 m-wrap" type="text" placeholder="<?php $array = explode(".",$file_name); echo $array[0] ?>" disabled=""><br>
<label>Text:</label>
<textarea class="span6 m-wrap" name="edit" cols="420" rows="10"><?php echo $contents ?></textarea><p>
<input type="hidden" name="file_name" value="<?php echo $file_name ?>">
<input class="btn red" type="submit" value="Update!">
</form>
如何使脚本检查文件名中是否有空格(例如 News 1.txt)并用 + 替换它们(例如 News+1.txt)?先感谢您。