0

I am attempting to put data from a CSV file and put it into a String variable in an HTML file. The HTML and CSV file are under the same local directory on my computer. In Java and C++, I know it is possible to read and write to a text file. So, when using JavaScript, PHP, jQuery, or anything else, is it possible to set the string in my HTML file equal to the data from a local CSV file? I need a way to read the CSV text into a Javascript variable string.

I have a program currently that parses CSV formatted text, but I need the text to be pulled from a CSV file. I have read numerous posts saying that this is not possible because of security reasons - is this the case? All of the answers that I have seen require the user to select the file the want to pull from. I just want it to automatically be pulled from a specific CSV file always.

  • Can do it using file input or drop zone in page and have FileReader API read file once selected or dropped – charlietfl Jul 22 '18 at 21:26
  • It's not possible to do so **using browser** . Browsers have security restrictions on doing that. However, it *is possible* to do so using node.js or something like Electron. You can write a small program in JS, run it on your computer and have that program read the file / calculate differences / store the results in MySQL and even notify your browser via websockets that something new has turned up. – N.B. Jul 22 '18 at 21:29

2 Answers2

0

I'm sorry to have to disappoint you, but all the other comments where right. An app running in a browser is strictly not allowed to access the local file system without any user interaction. For the formerly mentioned security reasons. There is no way around, though.

0

Everyone was right - it is impossible to do it the way I was trying. However, I decided to host a local server on my PC using Python, and it worked like a charm! Credit to: https://youtu.be/1OK4TJfCzdY .