PHP: Problem with reading Files
Posted
by mathiregister
on Stack Overflow
See other posts from Stack Overflow
or by mathiregister
Published on 2010-05-31T19:13:04Z
Indexed on
2010/05/31
19:23 UTC
Read the original article
Hit count: 171
php
hello guys,
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!
© Stack Overflow or respective owner