Ankündigung

Einklappen
Keine Ankündigung bisher.

PHP - Gallerie

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • PHP - Gallerie

    Hallo!

    Um Bilder aus einem Ordner auf meiner Webseite anzeigen zu lassen benutze ich folgenden Programmcode: ...s.u.
    Jetzt möchte ich noch, dass ein Bild welches mit $_width_max_ = 500 auf meinen Seite angezeigt wird, zusätzlich mit einem Link oder so in seiner vollen Größen (also $_width_max_ = 0) auf einen neuen leeren Seite angezeigt wird.

    Da ich nicht so erfahren bin, gelingt es mir nicht. Ich hoffe, dass mir einer weiterhelfen kann. :wink:

    Gruß, Frank


    PROGRAMMCODE
    ---------------------------------

    config.php:
    -------------

    <?
    // image directory
    $_images_dir_ = './';

    // min width of image
    $_width_min_ = 100 ;
    // odstep od zdjecia w poziomie
    $_vspace_ = 20 ;
    // odstep od zdjecia w pionie
    $_hspace_ = 20 ;
    // border of image
    $_border_ = 0;

    // sorting
    // SORT_ASC, SORT_DESC
    $_sort_ = SORT_ASC;


    // width of full image
    // if original width, set this variable to 0
    $_width_max_ = 500 ;

    // show filename below image
    // 1 = YES, 0 = NO
    $_filename_ = 1;

    // number of cols
    $_no_cols_ = 3;

    // number of images on the site ( = number rows x number cols)
    $_no_pics_per_page_ = 12;


    ?>


    index.php:
    --------------

    <?
    if(is_file('../config.cfg.php'))
    require '../config.cfg.php';
    else
    die('Error, no config file');

    if(!is_dir($_images_dir_))
    die('Error, no image directory');

    ?>
    <?php
    $location = "../../../";
    $title = "Konzerte";
    $title_1 = "Photos";
    $document = "Zita Swoon";
    $link = "concerts.php";
    $link_1 = "concerts_2.php";
    require ($location."head.inc");
    require ($location."content.inc");
    require ($location."config.php");
    ?>
    <?

    $time_start = microtime(true);


    $noimage = 0;

    if ($dh = opendir($_images_dir_)) {
    while (($f = readdir($dh)) !== false) {
    if((substr(strtolower($f),-3) == 'jpg') || (substr(strtolower($f),-3) == 'jpg'))
    {
    $imageinfo = getimagesize($_images_dir_.$f);
    $width = $imageinfo[0];
    $height = $imageinfo[1];
    $size = round(filesize($_images_dir_.$f)/1024,1).' KB';
    $noimage++;
    $images[] = array('filename' => $f, 'width' => $width, 'height' => $height, 'size' => $size);
    array_multisort($images, $_sort_, SORT_REGULAR);
    }
    }
    closedir($dh);
    }


    if($noimage)
    {

    if($_GET["img"] != '')
    {
    echo '<p class="name">'.$images[$_GET["img"]][filename].'</p>';
    if($images[$_GET["img"]][filename] != '')
    {

    if($_GET["img"])
    $_no_ = ceil(($_GET["img"]+1)/$_no_pics_per_page_);
    else
    $_no_ = 1;

    if($_GET["img"] == 0)
    $side = '<p class="link">upnext >></p>';
    elseif($_GET["img"] == ($noimage-1))
    $side = '<p class="link"><< prevup</p>';
    else
    $side = '<p class="link"><< prevupnext >></p>';
    echo $side.'<p align="center">[img]picture.php?img='.$images[$_GET[[/img]</p>'.$side;
    }
    }
    else
    {
    // echo $noimage.'
    '.print_r($images);
    if($noimage > $_no_pics_per_page_)
    $norows = ceil($_no_pics_per_page_/$_no_cols_);
    else
    $norows = ceil($noimage/$_no_cols_);

    $nopos = ceil($noimage/$_no_pics_per_page_);

    // echo $nopos;
    echo '<table border="0" align="center" cellpadding="0" cellspacing="0">
    ';

    if($_GET["no"] == "")
    $no = 1;
    else
    $no = $_GET["no"];


    $index=abs($no-1)*$_no_pics_per_page_;
    if(($noimage-$index)<$_no_pics_per_page_)
    $norows= ceil(($noimage-$index)/$_no_cols_);

    for($a = 1;$a<=$norows;$a++)
    {
    echo '
    <tr>
    ';
    for($b = 1;$b<=$_no_cols_;$b++)
    {
    if($images[$index][filename] != '')
    {
    echo '<td width="'.(2*$_vspace_+$_width_min_).'" valign="top" align="center">[img]picture.php?img='.$images[$index][filename].'[/img]
    ';
    if($_filename_)
    echo '<span class="name">'.$images[$index][filename].'</span>

    ';

    echo '</td>';
    $index++;
    }
    else
    echo '<td width="'.(2*$_vspace_+$_width_min_).'"></td>';
    }
    echo '</tr>
    ';
    }

    echo '
    </table>
    ';

    if($nopos>1)
    {
    echo '<p class="link">';
    for($i=1;$i<=$nopos;$i++)
    {
    if($i == $no)
    echo '<font>'.$i.'</font>';
    else
    echo ''.$i.'';
    }
    echo '</p>';
    }

    }



    }
    else
    die('No images in directory');


    $time_end = microtime(true);
    $time = $time_end - $time_start;

    require ($location."content_end.inc");
    require ($location."foot.inc");
    ?>


    und.... pictue.php:
    -----------------------

    <?

    if(is_file('../config.cfg.php'))
    require '../config.cfg.php';
    else
    die('Error, no config file');

    if($_GET[img] == "")
    exit;

    if (!ereg('^[^./][^/]*$', $_GET[img]))
    exit;

    $_image_ = $_images_dir_.$_GET[img];
    $new_w = $_width_min_;
    $imagedata = getimagesize($_image_);

    // echo $_image_;
    if(!$imagedata[0])
    exit();


    $new_h = (int)($imagedata[1]*($new_w/$imagedata[0]));

    if($_GET["show"] == "full")
    {
    if($_width_max_)
    {
    if($imagedata[0]<$_width_max_)
    {
    $new_w = $imagedata[0];
    $new_h = $imagedata[1];
    }
    else
    {
    $new_w = $_width_max_;
    $new_h = (int)($imagedata[1]*($new_w/$imagedata[0]));
    }
    }
    else
    {
    $new_w = $imagedata[0];
    $new_h = $imagedata[1];
    }
    }


    if(strtolower(substr($_GET[img],-3)) == "jpg")
    {
    header("Content-type: image/jpg");
    $dst_img=ImageCreate($new_w,$new_h);
    $src_img=ImageCreateFromJpeg($_image_);
    $dst_img = imagecreatetruecolor($new_w, $new_h);
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_ w,$new_h,ImageSX($src_img),ImageSY($src_img));
    $img = Imagejpeg($dst_img);
    }

    if(substr($_GET[img],-3) == "gif")
    {
    header("Content-type: image/gif");
    $dst_img=ImageCreate($new_w,$new_h);
    $src_img=ImageCreateFromGif($_image_);
    ImagePaletteCopy($dst_img,$src_img);
    ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w, $new_h,ImageSX($src_img),ImageSY($src_img));
    $img = Imagegif($dst_img);
    }


    ?>

  • #2
    Hallo noch mal,

    Konkret liegt mein Problem darin dass ich eine gesetzte Variable ($_width_max_ = 500) mit dem klick auf einem link verändern ($_width_max_ = 0) möchte, es aber nicht hinbekomme.

    Danke und Gruß, Frank.

    Kommentar


    • #3
      Machs einfach so
      PHP-Code:
      if(isset($_GET['width_max']) AND !empty($_GET['width_max'])
      {
          
      $_witdh_max_ = $_GET['width_max'];
      } else {
          
      $_width_max_ = 500;
      } 

      Kommentar

      Lädt...
      X