I want multiple image types to pass my check. But I dont know why my new code doesnt work. Could anyone help me.
Old code (works but only with jpg)
<?php
$dir = "img/";
$ispis = "";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (preg_match("/.jpg/", $file)) {
$putanja = $dir . $file;
$ispis .= "<li><a href='" . $putanja . "'><img width='100px' height='100px' src='" . $putanja . "'></a></li>";
}
}
closedir($dh);
}
}
include '_header.php';
?>
I want it to pass all the types I want. How can I make it check all of these:
$formati = array("jpg", "png", "gif", "bmp");
New code (doesnt work)
<?php
$dir = "img/";
$ispis = "";
$formati = array("/.jpg/", "/.png/", "/.gif/", "/.bmp/");
$brojformata = sizeof($valid_formats);
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
for( $i = 0; $i < $brojformata; $i++) {
if (preg_match($formati[$i], $file)) {
$putanja = $dir . $file;
$ispis .= "<li><a href='" . $putanja . "'><img width='100px' height='100px' src='" . $putanja . "'></a></li>";
}
}
}
closedir($dh);
}
}
include '_header.php';
?>