0

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

1
  • Just use AJAX get calls to retrieve the text files, and create a new <div> with a header containing the filename, and a paragraph containing the retrieved text. Commented May 19, 2011 at 23:36

3 Answers 3

1

have you checked out jquery's load function? i think it will do what you want.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

For PHP it's pretty simple.

$file = 'path/to/file/';    
$contents = fread($file,'r');
fclose($file);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.