首页 > 解决方案 > 将组合框中的文件加载到文本字段中

问题描述

我正在尝试将选定的文本文件从组合框中加载到文本框中。按下按钮时,我将文件内容的显示插入到文本框中,但文本框中没有显示任何内容。我不知道如何解决它。请帮忙,提前谢谢

<?php

$path = "books/";
$books = opendir($path);  
while (($book = readdir($books)) !== false)                     
{
    if(substr($book, -4) === ".txt") {
        $filePath = $path.$book;
        echo $filePath;
        
        $theList .= '<option><a href="'.$filePath.'">'.$filePath.'</a>';
        
        $openFile = fopen($filePath, "r") or die("Permission error");
        $readBook = file_get_contents($filePath);
        echo $readBook;
        echo "<br>";
        fclose($openFile);
    }
    
}
closedir();                                                             

?>
<html>
    <head>
        <title>Books Form</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="jquery-3.6.0.js"></script>        
        <style>
            
        </style>
    </head>
    <body>        
        <form method="POST" action="" id="bookform">
            <label for="books"></label>
            <select name="book" id="books" form="bookform">
                <option value=""><?=$theList?></option>
            </select><br><br>
            <button style="position: relative; left: 240px" name="onClick" class="click" type="submit" form="form" value="">Wczytaj</button><br><br>
        </form>
        <div>
            <textarea name="info" class="form-test" rows="30" cols="100">
                <?php 
                if(isset($_POST['onClick']))
                    {
                        $readBook = file_get_contents($filePath);
                        echo $readBook;
                        //print_r($readBook);
                    } 
                    ?>
            </textarea><br>
        </div>
        <form>
            <button type="submit" form="form" value="Submit">Zapisz</button><br>
        </form>
    </body>
</html>

标签: phphtml

解决方案


推荐阅读