开发者

PHP: Problem with reading Files

i wonder what i'm doing wrong! i want to read a folder and run through the existing files, checking if they are either images or textfiles.

if there are textfiles they should be put into a div, if there are images the should be output as an image.

<?php
$path = 'thumbs';
if ($handle = opendir($path)) {
    while (false !== ($file = readdir($handle))) {
        $ext = pathinfo($file, PATHINFO_EXTENSION);
            if ($ext == "jpg" || $ext == "jpeg" || $ext == "gif" || $ext == "png") {
                print "<img class='thumb' src='$path/$file'/>";
            } else if ($ext == "txt" || $ext == "rtf") {
                //read text
                $lines = file_get_contents($file);
            开发者_如何转开发    $lines = str_replace("\n","<br/>",$lines);
                print "<div class='text'>" . $lines . "</div>";
                //read text
            }
    }
    closedir($handle);
}
?>

there seems to be a problem i can't find, because ALL IMAGES get put out, however only ONE of a few textfiles gets printed. Any ideas why it only prints out one textfile???

thank you for your help!


Depending on where this is being run from it may not know the path to the file...try something like this:

$lines = file_get_contents($path . '/' . $file);  


Are you sure there are more than one txt or rtf files in thumbs directory?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜