我的索引页面有一个输入字段,您可以在其中创建文件。在此输入字段下,我有一个包含所有已创建文件的表,如下所示:
Title | Edit | Delete |
denis.txt Edit Delete
所以我想做'东西'(我不知道怎么做),所以表格中的标题(denis.txt)要不显示扩展名(.txt)。
这是我的索引文件:
<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>
</div>
</form>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Заглавие</th>
<th style="align: center; width: 12%"><div align="center">Редактирай</div></th>
<th style="align: center; width: 12%"><div align="center">Изтрий</div></th>
</tr>
</thead>
<tbody>
<?php
echo $_POST['edit'];
$full_path = ".";
$dir = @opendir($full_path) or die("Директорията не може да се отвори.");
while($file = readdir($dir))
{
if($file == "components" || $file == "index-restricted.php" || $file == "index-error.php" || $file == "generalsettings-success.php" || $file == "exampic" || $file == "all_count.txt" || $file == "assets" || $file == "count_vhod.txt" || $file == "count_nachalo.txt" || $file == "index-invalid.php" || $file == "news-delok.php" || $file == "images" || $file == "auth.php" || $file == "php" || $file == "news.php" || $file == "sponsors.php" || $file == "upload" || $file == "js" || $file == "img" || $file == "dashboard.php" || $file == "logout.php" || $file == "ajax" || $file == "prettify" || $file == "log.php" || $file == "css" || $file == "generalsettings.php" || $file == "nachaloadm.php" || $file == "php_errorlog" || $file == "fonts" || $file == "sql.php" || $file == "edit_file.php" || $file == "delete.php" || $file == "create_file.php" || $file == ".." || $file == "index.php" || $file == "." || $file == "edit.php")
continue;
?> <?php
echo "<tr><td><a href='$file'>$file</a></td><td><a href='edit.php?name=$file' class='btn mini purple'><div align='center'><i class='icon-edit'></i> Редактирай</div></a></td><td><div align='center'><a href='delete.php?name=$file' class='btn mini black'><div align='center'><i class='icon-trash'></i> Изтрий</div></a></div></td></tr>";
}
closedir($dir);
?>
</tbody>
</table>
这是我的 create_file.php:
<?php
$pre_file_name = $_POST['name'];
$ext = ".txt";
$file_name = $pre_file_name.$ext;
fopen($file_name,'w');
?>
<form class="stdform stdform2" action="edit_file.php" method="POST">
<label>Въведете новината (текст):</label><span class="field"><textarea class="input-xxlarge" name="edit" cols="1600" rows="10"></textarea></span><p>
<input type="hidden" name="file_name" value="<?php echo $file_name; ?>">
<p class="stdformbutton">
<input class="btn btn-primary" type="submit" value="Създай!">
</p>
</form>
这是我的edit_file.php:
<?php
$edit = $_POST['edit'];
$file_name = $_POST['file_name'];
$file = fopen($file_name, 'w');
fwrite($file,$edit);
fclose($file);
echo "File Saved! <a href='index.php'>Click here to continue</a>"
?>
我的一个朋友给我写了以下内容:
"If you use the explode function to separate the file name from the extension. So:
$array = explode(".",$file);
Then you can echo out:
echo $array[0]; which will give you the file name without the extension.
You may get some problems with this though if you have a dot in the file name, so more than one dot. But who uses dots in the file name anyway, but its something to think about.
Also this method might not be best with the while loop looping round the files in the readdir function.
You may be better using the scandir function which puts the files into any array then you can use a for each loop to loop through the array."
但我不知道如何使它工作。PS 我想它也可以用 $_SESSION 制作,但要么不知道如何制作:(
问候, 丹尼斯赛多夫