如何一次获取一行文件的内容?

I have a project where a user uploads a photo with a name and caption, and I am having trouble with displaying the name and caption.

Right now, it's displaying the entire text file with each image, and I am having trouble fixing this.

My code so far:

    <?php
        $Dir = "files";
        $DirEntries = scandir($Dir);
        foreach ($DirEntries as $Entry)
        {
            if((strcmp($Entry, '.') != 0) && (strcmp($Entry, '..') != 0))
            {
                echo "<p>Name: " . file_get_contents("imagelist.txt") . "</p>";
                echo "<a href=\"files/" . $Entry . "\" target=\"_blank\" >" . $Entry . "</a><br />
";  
            }
        }
        closedir($DirOpen);         
    ?>

Any help would be greatly appreciated.

You can use fgets():

$inputFile = fopen("file.txt", "r");
if ($inputFile) {
    while (($line = fgets($inputFile)) !== false) {
        echo $line."<br>";
        // The process read the file line by line        
    }
} else {
    echo "There was an error in the opening file";
} 
fclose($inputFile);