开发者

PHP - loading file from DIR

开发者 https://www.devze.com 2023-02-17 17:38 出处:网络
I wrote PHP sctipt which loading images from DIR and display a picture.. directory = \'../../gallery/glowna\';

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:ri开发者_运维技巧ght; 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 ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号