carbide20 Posted December 15, 2007 Share Posted December 15, 2007 Hi, I'm trying to write a script that reads in .png files from a folder, and displays them as links to folders with their names. ie: an 'img' folder contains 'test1.png' and 'test2.png' and it would load in those images, and make them link to the folders: 'test1/' and 'test2/' I got it all working (using an array so I can sort them alphabetically), but it dosent seem to be letting me check if they are .png files. <?php $cols = 7; //Total Columns $dir = "img/sections/"; //Game Dir $dh = opendir($dir); $count = 1; while($file = readdir($dh)) { if($file != ".." AND $file != ".") { $sectionArray[] = $file; } } echo "<table cellpadding='0' cellspacing='0'><tr>"; //loop through the dir foreach($sectionArray as $section) { $name = explode(".", $section, -1); $first = $name[0]; // THIS IS THE PART THAT DOES NOT WORK!!! $last = $name[1]; if ($last == "png"){ // END PART THAT DOES NOT WORK!!! //Output everything echo "<td align='center' valign='top' width='" . 100 / $cols . "%'><br /><a href='sections/" . $first . "'><img src='" . $dir . $section . "' border='0'/></a></td>"; //End row, or increment count if($count >= $cols) { echo "</tr><tr>"; $count = 1; } else { $count++; } } } closedir($dh); echo "</tr></table><br />"; ?> Link to comment https://forums.phpfreaks.com/topic/81841-image-array/ Share on other sites More sharing options...
phpQuestioner Posted December 15, 2007 Share Posted December 15, 2007 look into "image_type_to_extension" http://us2.php.net/manual/en/function.image-type-to-extension.php Link to comment https://forums.phpfreaks.com/topic/81841-image-array/#findComment-415800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.