title: How can I read a .txt file with Javascript(or PHP) and insert the contents into an html webpage?
body: <p>I have spent many hours trying to figure this out, though it seems it should be quite straightforward. I'm working on a website with a javascript file that generates html code given the pathname of a folder. Currently I am able to pull images from those folders no problem, but am trying to figure out .txt files...</p>
  
  <pre><code>document.write('&lt;img src="folder/' + info[i] + '/picture.png"&gt;');
  </code></pre>
  
  <p>info[i] is an array storing the name of each folder I want to grab files from...</p>
  
  <p>So in every folder there is an image called picture.png, there is also a text file called details.txt</p>
  
  <p>Is it possible to have something like...</p>
  
  <pre><code>var details;
  details = readFile('"folder/' + info[i] + '/details.txt"');
  document.write(details);
  </code></pre>
  
  <p>I have also tried the following code, I simply can't get the .txt contents to showup in the browser. The .txt file has words in it, and is in the same folder as the html file...
  If I can get the code below to work and display the file on the webpage, then I'll be able to answer the rest of my question.</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  Contents:
  
  &lt;?php $file_content = file_get_contents('details.txt'); ?&gt;
  
  &lt;script type="text/javascript"&gt;
  
  var details = '&lt;?php echo $file_content ; ?&gt;';
  
  document.write(details);
  
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thank you for your time, any help is greatly appreciated.</p>