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.
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.