Reputation: 1
I wrote PHP sctipt which loading images from DIR and display a picture..
directory = '../../gallery/glowna';
$thumb = '../../gallery/glowna';
$allowed_types=array('jpg','jpeg','gif','png');
$file_parts=array();
$ext='';
$title='';
$i=0;
$dir_handle = @opendir($directory) or die("Błąd ! Skontaktuj się z administratorem SERWISU...");
while ($file = readdir($dir_handle))
{
if($file=='.' || $file == '..') continue;
$file_parts = explode('.',$file);
$ext = strtolower(array_pop($file_parts));
$title = implode('.',$file_parts);
$title = htmlspecialchars($title);
$nomargin='';
if(in_array($ext,$allowed_types))
{
if(($i+1)%3==0) $nomargin='nomargin';
echo '
<div class="pic '.$nomargin.'" style="background:url('.$thumb.'/'.$file.') no-repeat ; background-position:top center;">
<form method="post" action="delete.php">
<input type="checkbox" name="usun" value="'.$file.'" style="visibility:hidden;" checked="checked"/>
<input type="submit" name="submit" value="kasuj" style="float:right; font-size:9px; border:none; " />
</form>
</div>';
$i++;
}
}
$usunac = $_POST['.$file.'];
closedir($dir_handle);
?>
But in folder I have thumbs and big photos, I want display only thumb and it's a problem..
How can I add function displaing only images whith 'thumb_' prefix ?
Upvotes: 0
Views: 221
Reputation: 1001
You could change this line:
if($file=='.' || $file == '..') continue;
to the line:
if ($file=='.' || $file == '..' || !preg_match("/^thumb/",$file)) continue;
which would make it skip the while loop if it the file didn't begin with thumb.
Upvotes: 2