Grabbing text from text files with JavaScript
I开发者_运维知识库 have tons of text files from which ones I want to grab the text and display it on one webpage. Also I would like to have the file name of those files added at the top of every text grabbed.
e.g:
file name
text from file name
file name
text from file name
...
Any idea how can I do this using JavaScript?
If is not js I'll be happy with php as well.
Thanks :) Vic
have you checked out jquery's load function? i think it will do what you want.
From client side javascript, you can't do this as you can't get a list of all the text files. It would also be very slow.
For php, see the opendir() function to get the list of files, and the readfile() function to display their contents.
For PHP it's pretty simple.
$file = 'path/to/file/';
$contents = fread($file,'r');
fclose($file);
精彩评论