我目前丢失了概述,看不到我的失败。在这种情况下你能帮我吗?
在第一次加载时,我选择要编辑的html文件。我保存到变量“$ datei”中的所选文件的名称。按下“保存”按钮后,我想保留变量“$ datei”。我的问题是我无法解决我选择的文件留在哪里。它总是跳到“Dateiusauwählen......”。 我真的没有计划如何将所选文件设置到下拉列表中以保留所选文件。
<html>
<head>
<script src="./ckeditor/ckeditor.js"></script>
</head>
<body>
<?php
session_start();
$_SESSION = $_POST;
$_SESSION['dirname'] = "templates";
$_SESSION['new'] = 0;
//$_SESSION['selectedfile'] = $_POST['selectedfile'];
$dirname = $_SESSION['dirname'];
if ($_SESSION["new"] != 1 ){
//$dirname = "templates";
$dir = opendir($dirname);
echo '<form name="displayfile" action="" method="POST">';
echo '<select name="file2">';
echo '<option value="">Datei auswählen...</option>';
while(false != ($file = readdir($dir)))
{
if(($file != ".") and ($file != ".."))
{
echo "<option value=".$file.">$file</option>";
}
}
echo '</select>';
echo '<input type="submit" value="Datei laden" />';
}
//file2 is the name of the dropdown
//$dirname = "templates";
$_SESSION['selectedfile'] = @$_POST['file2'];
$selectedfile = $_SESSION['selectedfile'];
$_SESSION['selectedfile'] = $selectedfile;
$datei = $dirname . '/' . $selectedfile;
$content = file($dirname . '/' . $selectedfile);
$data = implode("<br>",$content);
echo $datei;
$_SESSION['datei'] = $datei;
echo $_SESSION['datei'];
//Auf den Button Save wurde gedrückt
if( isset( $_REQUEST['save'] ))
{
echo $_SESSION['datei'];
$dirname = $_SESSION['dirname'];
$selectedfile = $_SESSION['selectedfile'];
$_SESSION['selectedfile'] = $selectedfile;
echo "<br />datei=" . $datei . "<br />";
echo "data=" . $data . "<br />";
echo "data=" . $data . "<br />";
echo "selectedfile=" . $_SESSION['selectedfile'] . "<br />";
//file_put_contents($datei, $data, LOCK_EX);
}
?>
<textarea class="ckeditor" name="editor"><?php echo $data; ?></textarea>
<input type="submit" name="save" value="Speichern" />
</form>
</body>
</html>