<?php
$file = file("config.txt");
$fname="test.txt";
for ($i = 0; $i < count($file);$i++)
{
$f = substr($file[$i],0,strlen($file[$i])-1);
echo "<div style=\"color:blue;text-decoration: underline;\" onclick=\"click_link('$f')\">$file[$i]</div>";
}
echo "<br>";
if ($_POST["open"])
{
$fname=$_POST['fname'];
/////////////
$found = 1;
$file = file("config.txt");
for ($i = 0; $i < count($file);$i++)
{
if ($file[$i] == $fname."\n")
{
$found = 2;
}
}
if ($found == 1)
{
$hdle = fopen("config.txt", "a+");
fwrite($hdle, $_POST['fname']."\n");
}
////////////////
if (file_exists($_POST['fname'])) {
$handle = fopen($_POST['fname'], "r");
if (filesize($_POST['fname']) > 0){
$text = fread($handle, filesize($_POST['fname']));
}
}
else
{
file_put_contents($_POST['fname'],"");
}
}
if ($_POST["save"])
{
$fname=$_POST['fname'];
$handle = fopen($_POST['fname'], "w");
fwrite($handle, $_POST['textcontent']);
$st = "файл сохранен";
}
?>
<form method="post">
Путь к файлу
<br>
<textarea style="resize: none;" type="text" name="fname" id="fname"><?php echo $fname;?></textarea>
<br>
<input type="submit" name="open" value="открыть текст">
<br>
<textarea name="textcontent" cols="80" rows="25"><?php echo $text;?></textarea>
<br>
<input type="submit" name="save" value="сохранить текст"><div name="st"> <?php echo $st;?> </div>
<br>
</form>
<script>
function click_link(ffile){
var element = document.getElementById("fname");
element.value = ffile;
}
</script>
|