Search code examples
phptext-filesreaddir

PHP / read txt files (or anything)


I've been searching for a while now, but php-noob as I am, can't get it to work.

What I'm trying to accomplish is a way to make directories in your root, with in each of them images + a txt file. So let's say you got:

 Root
 |
 +---Directory 1
 |   |
 |   +---Image1.jpg
 |   |
 |   +---Image2.jpg
 |   |
 |   +---Text.txt
 |
 +---Directory 2
     |
     +---Image1.jpg
     |
     +---Image2.jpg
     |
     +---Text.txt

I know how to read and display the images + names. But how do I display the accompanied textfile? (The content that is, not the title of the file).

Much appreciated!


Solution

  • the easiest way is using file_get_contents ( http://php.net/manual/en/function.file-get-contents.php )

    echo file_get_contents($path_to_file);
    

    More advanced: fopen/fread http://php.net/manual/en/function.fread.php