doutuo1939 2019-02-27 06:37
浏览 110

如何读取html文件中的文本文件,并使用php将内容复制到变量中

I'm new to HTML and when I searched for various ways of reading a text file inside HTML file, I found this code :

<!DOCTYPE html>
<html>
    <head>
      <meta charset="UTF-8">
      <title>Page Title</title>
    </head>
<body>
<?php
    $myfile = fopen("C:\Users
uh\Documents\webdictionary.txt", "r") or die("Unable to open file!");
    echo fgets($myfile);
    fclose($myfile);
?>
</body>
</html>

The PHP code does not run inside HTML.

Using javascript, I could not find a code which reads each line into a variable. Please suggest me another way to read the contents into a variable.

  • 写回答

1条回答 默认 最新

  • dskm94301 2019-02-27 06:55
    关注

    For security purpose, javascript and HTML can't access the user filesystem.

    If the file you try to read is on the server you can simply use readfile("C:\Users uh\Documents\webdictionary.txt");

    If the file is on the client side then there is no way you can access it from PHP directly. You have to use a form with file input and submit it to your PHP. This way the user will have to click and to choose the file and you will have to manage the content of the request.

    I don't know about any 3rd party plugin to do it.

    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗