-1

私のインデックス ページには、ファイルを作成できる入力フィールドがあります。この入力フィールドの下に、次のように、作成されたすべてのファイルのテーブルがあります。

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>&nbsp;&nbsp;Редактирай</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>&nbsp;&nbsp;Изтрий</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 でも作成できると思いますが、作成方法がわかりません:(

よろしく、 デニス・サイドフ

4

1 に答える 1

1

これがテーブルを出力するコードだと思います:

  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>&nbsp;&nbsp;Редактирай</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>&nbsp;&nbsp;Изтрий</div></a></div></td></tr>";

拡張機能を削除するには、pathinfo()を使用できます。

echo pathinfo("aaa.txt", PATHINFO_FILENAME);

したがって、コードは次のようになります。

echo "<tr><td><a href='$file'>". pathinfo($file, PATHINFO_FILENAME) ."</a></td><td><a href='edit.php?name=$file' class='btn mini purple'><div align='center'><i class='icon-edit'></i>&nbsp;&nbsp;Редактирай</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>&nbsp;&nbsp;Изтрий</div></a></div></td></tr>";
于 2013-03-16T20:29:20.447 に答える