php - Scandir variable not a string? -
i have piece of php code lists directories , creates div's information regarding directories inside of it. when $newspieces[i] doesn't include name of folder in string, why?
<?php $newspieces = scandir("posts"); ($i = 2; $i < count($newspieces) , $i < 10; $i++) { $titlefile = fopen($newspieces[i] . "/title.txt", "r"); $textfile = fopen($newspieces[i] . "/text.txt", "r"); $fullelement = "<div class='newspiece'><div class='newsimageholder'><img class='newsimage' src='" . $newspieces[i] . "/image.jpg'></div><div class='newscontent'><h1 class='newstitle'>" . fread($titlefile, filesize($newspieces[i] . "/title.txt")) . "</h1><p class='newstext'>" . $piece[] = fread($textfile, filesize($newspieces[i] . "/text.txt")) . "</p><a class='newslink' href='post?post=" . urlencode($newspieces[i]) . "'>continue reading</a></div></div>"; echo $fullelement; fclose($titlefile); fclose($textfile); } ?>
fixed version:
<?php $newspieces = scandir("posts"); ($i = 2; $i < count($newspieces) , $i < 12; $i++) { $titlefile = fopen("posts/" . $newspieces[$i] . "/title.txt", "r") or die("unable open file!"); $textfile = fopen("posts/" . $newspieces[$i] . "/text.txt", "r") or die("unable open file!"); $fullelement = "<div class='newspiece'><div class='newsimageholder'><img class='newsimage' src='posts/" . $newspieces[$i] . "/image.jpg'></div><div class='newscontent'><h1 class='newstitle'>" . fread($titlefile, filesize("posts/" . $newspieces[$i] . "/title.txt")) . "</h1><p class='newstext'>" . fread($textfile, filesize("posts/" . $newspieces[$i] . "/text.txt")) . "</p><a class='newslink' href='post?post=" . urlencode($newspieces[$i]) . "'>continue reading</a></div></div>"; echo $fullelement; fclose($titlefile); fclose($textfile); } ?>
Comments
Post a Comment