Промняна на галерия

beta16

Registered
може ли да премахнете цялата част за категориите и да може да имам по 7 снимки на ред ето го кода
Код:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>PHP Галерия</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>

<body>

<?php

// КОНФИГУРАЦИЯ //

$pics_folder = "pics"; // в коя папка са картинките и категориите
$max_width = 150; // максимална широчина
$max_height = 150; // максимална височина
$pics_per_page = 25; // по колко картинки на страница
$pics_ex = array('jpg','jpeg','gif','png'); // кои файлове да зачита като картинки

// КРАЙ НА КОНФИГУРАЦИЯТА //

function resize($pic)
{
    global $max_width, $max_height;
    $max_width_pic = $max_width;
    $max_height_pic = $max_height;
    list($width,$height) = getimagesize($pic);
    $ratio = $width / $height;
   
    if ($width > $max_width_pic || $height > $max_height_pic)
    {
        if ($width > $height)
        {
            $width = $max_width_pic;
            $height = $width / $ratio;
        }
        elseif ($width < $height)
        {
            $height = $max_height_pic;
            $width = $height * $ratio;
        }
        elseif ($width == $height)
        {
            $width = $max_width_pic;
            $height = $max_height_pic;
        }
    }
    $width = intval($width);
    $height = intval($height);
    return array("width" => $width, "height" => $height);
}

$pics_folder = preg_replace('/[\/]+/', '/', $pics_folder.'/');

function all_images()
{
    global $pics_folder, $pics_ex;
    $folders = array($pics_folder);
    $checked = array($pics_folder);
    $out_files = array();
    while (count($folders))
    {
        foreach ($folders as $folder)
        {
            array_shift($folders);
            $dir = opendir($folder);
            while ($file = readdir($dir))
            {
                if ($file != '.' && $file != '..')
                {
                    if (is_file($folder.$file) && in_array(strtolower(end(explode(".", $file))), $pics_ex))
                    {
                        $out_files[] = $folder.$file;
                    }
                    elseif (is_dir($folder.$file) && !in_array($folder.$file.'/', $checked))
                    {
                        $folders[] = $folder.$file.'/';
                        $checked[] = $folder.$file.'/';
                    }
                }
            }
        }
    }
    return $out_files;
}

$all_images = all_images();

$category = false;
if (preg_match('/^[a-zа-я]+((->)[a-zа-я]+)*$/i', $_GET['kat']))
{
    $category = (is_dir($pics_folder.str_replace('->', '/', $_GET['kat']))) ? str_replace('->', '\/', $_GET['kat']) : false;
}

$out_images = array();
foreach ($all_images as $image)
{
    $raz = explode("/", $image);
    array_shift($raz);
    array_pop($raz);
   
    if ($category && !preg_match("/^$category/", implode("/", $raz))) continue;
    $out_images[] = $image;
}

$masiv = @array_chunk($out_images, $pics_per_page, true);

$stranici = floor(count($out_images) / $pics_per_page);
if ((count($out_images) % $pics_per_page) > 0) { $stranici++; }

if (is_numeric($_GET['page']) && $_GET['page'] <= $stranici) {
    $page = $_GET['page'];
} else {
    $page = 1;
}

$red = 1;
echo "<table border=\"0\">
<tr>\n";
foreach ($masiv[($page - 1)] as $pic)
{
    $resize = resize($pic);
    $razp = explode("/", $pic);
    array_shift($razp);
    array_pop($razp);
   
    $kat = array();
    for ($i=0;$i<count($razp);$i++)
    {
        $url = array();
        for($i2=0;$i2<=$i;$i2++)
        {
            $url[] = $razp[$i2];
        }
        $kat[] = '<a href="?kat='.implode("->", $url).'">'.$razp[$i].'</a>';
    }
   
    echo "<td><a href=\"{$pic}\" target=\"_blank\"><img src=\"{$pic}\" width=\"".$resize['width']."\" height=\"".$resize['height']."\" border=\"0\"></a><br />Категория:<br />".((count($kat)) ? implode(" -> ", $kat) : "Няма")."</td>\n";
    if ($red == floor(sqrt($pics_per_page))) { $red = 1; echo "</tr><tr>\n"; } else { $red++; }
}
echo "</tr>
</table>";

echo "<br><br><br />Страници: ";
for ($i=1;$i<=$stranici;$i++) {
    if ($page != $i) {
        echo "<a href=\"?page=$i".(($category) ? '&kat='.$_GET['kat'] : '')."\">$i</a> ";
    } else {
        echo "$i ";
    }
}
?>
 
Код:
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>PHP Галерия</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>

<body>

<?php

// КОНФИГУРАЦИЯ //

$pics_folder = "pics"; // в коя папка са картинките и категориите
$max_width = 150; // максимална широчина
$max_height = 150; // максимална височина
$pics_per_page = 7; // по колко картинки на страница
$pics_ex = array('jpg','jpeg','gif','png'); // кои файлове да зачита като картинки

// КРАЙ НА КОНФИГУРАЦИЯТА //

function resize($pic)
{
    global $max_width, $max_height;
    $max_width_pic = $max_width;
    $max_height_pic = $max_height;
    list($width,$height) = getimagesize($pic);
    $ratio = $width / $height;
   
    if ($width > $max_width_pic || $height > $max_height_pic)
    {
        if ($width > $height)
        {
            $width = $max_width_pic;
            $height = $width / $ratio;
        }
        elseif ($width < $height)
        {
            $height = $max_height_pic;
            $width = $height * $ratio;
        }
        elseif ($width == $height)
        {
            $width = $max_width_pic;
            $height = $max_height_pic;
        }
    }
    $width = intval($width);
    $height = intval($height);
    return array("width" => $width, "height" => $height);
}

$pics_folder = preg_replace('/[\/]+/', '/', $pics_folder.'/');

function all_images()
{
    global $pics_folder, $pics_ex;
    $folders = array($pics_folder);
    $checked = array($pics_folder);
    $out_files = array();
    while (count($folders))
    {
        foreach ($folders as $folder)
        {
            array_shift($folders);
            $dir = opendir($folder);
            while ($file = readdir($dir))
            {
                if ($file != '.' && $file != '..')
                {
                    if (is_file($folder.$file) && in_array(strtolower(end(explode(".", $file))), $pics_ex))
                    {
                        $out_files[] = $folder.$file;
                    }
                    elseif (is_dir($folder.$file) && !in_array($folder.$file.'/', $checked))
                    {
                        $folders[] = $folder.$file.'/';
                        $checked[] = $folder.$file.'/';
                    }
                }
            }
        }
    }
    return $out_files;
}

$all_images = all_images();

$category = false;
if (preg_match('/^[a-zа-я]+((->)[a-zа-я]+)*$/i', $_GET['kat']))
{
    $category = (is_dir($pics_folder.str_replace('->', '/', $_GET['kat']))) ? str_replace('->', '\/', $_GET['kat']) : false;
}

$out_images = array();
foreach ($all_images as $image)
{
    $raz = explode("/", $image);
    array_shift($raz);
    array_pop($raz);
   
    if ($category && !preg_match("/^$category/", implode("/", $raz))) continue;
    $out_images[] = $image;
}

$masiv = @array_chunk($out_images, $pics_per_page, true);

$stranici = floor(count($out_images) / $pics_per_page);
if ((count($out_images) % $pics_per_page) > 0) { $stranici++; }

if (is_numeric($_GET['page']) && $_GET['page'] <= $stranici) {
    $page = $_GET['page'];
} else {
    $page = 1;
}

$red = 1;
echo "<table border=\"0\">
<tr>\n";
foreach ($masiv[($page - 1)] as $pic)
{
    $resize = resize($pic);
    $razp = explode("/", $pic);
    array_shift($razp);
    array_pop($razp);
   
    $kat = array();
    for ($i=0;$i<count($razp);$i++)
    {
        $url = array();
        for($i2=0;$i2<=$i;$i2++)
        {
            $url[] = $razp[$i2];
        }
        $kat[] = '<a href="?kat='.implode("->", $url).'">'.$razp[$i].'</a>';
    }
   
    echo "<td><a href=\"{$pic}\" target=\"_blank\"><img src=\"{$pic}\" width=\"".$resize['width']."\" height=\"".$resize['height']."\" border=\"0\"></a><br />".((count($kat)) ? implode(" -> ", $kat) : "")."</td>\n";
    if ($red == floor(sqrt($pics_per_page))) { $red = 1; echo "</tr><tr>\n"; } else { $red++; }
}
echo "</tr>
</table>";

echo "<br><br><br />Страници: ";
for ($i=1;$i<=$stranici;$i++) {
    if ($page != $i) {
        echo "<a href=\"?page=$i".(($category) ? '&kat='.$_GET['kat'] : '')."\">$i</a> ";
    } else {
        echo "$i ";
    }
}
?>
:twisted:
 
нито едно от двете работи не е направено показва по две снимки на ред и на прав поглед си личи че имам части от категориите
 

Горе