将文件参数直接传递给 FileReader

Passing file parameter directly to FileReader

我正在尝试为学校关闭制作网页,所以我必须使用 javascript 写入文件。我一直在查看 FileReader,但我找不到将 link 传递给文件的方法,而不是使用来自输入或其他任何变量的变量。我是 javascript 世界中的菜鸟,所以我无法向您描述太多,但这是代码:

<head>
        <title>
            Ohio School Closings Home
        </title>
        <style>
            body{
                text-align: center;
            }
        </style>
        <script>

            var reader = new FileReader();
            var closingsFile = reader.readAsText('closings.txt');
            document.getElementById("textContents").innerHTML = closingFile;

            function test(){
                alert("javascipt is working");
            }
        </script>
    </head>
    <body>
        <h1>Ohio School Closings</h1>
        <h4><a href="search.html">Search</a>-<a href="apps.html">App</a>-<a href="admincontrol.html">Admin Control Panel</a></h4>
        <br>
        <h2>Current Closings</h2>
        <p id="textContents">There are currently no closings</p>
        <h2><a href="http:\www.facebook.com\ohioschoolclosings">Facebook</a></h2>
        <button onClick="test()">Test Javascript<!--Checks for syntax errors temporarilly, will be removed--></button>

我决定使用PHP来读写服务器上的文件。


将 $filename 替换为文件路径

//READ FILE
$file = fopen($filename, "r");
$filecontents = fread($file, filesize($filename));

echo nl2br($filecontents); //if you want to display the text as it would appear in the file