Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z galeria zdjec.
Forum PHP.pl > Forum > Gotowe rozwiązania
kpjeziorak
Mam zastosowany nastepujacy szablon php na stronie:
[php:1:16de3b2c9d]<?php
if(!isset($page)) {
$page="index";
}
if(file_exists("dzialy/$page.php")) {
include "dzialy/$page.php";
} else {
echo "Strona w budowie!";
}
?>[/php:1:16de3b2c9d]

Link do dzialu wyglada nastepujaco:
Kod
<A HREF="index.php?page=dzial" class="menu">dzial</A>


Gdy moja galeria wrzuce na zwylka strone (nie includuje) to jest ok, wyswietla fotki i wszystko dziala, zas gdy uzyje linku, jaki pokazalem wyzej zdjecia nie wyswietlaja sie:( Oto skrypt galerii:
[php:1:16de3b2c9d]<?php
<?
////////////////////////////////////////////////////////////////////////////////////////////////////////
// NAME:
// imagebrowser.php
//
// VERSION:
// Version 1.0 - 18/07/01
//
// Version 1.2 - 05/10/01 (Jeremy.Bouse@UnderGrid.net)
// - Cleaned up HTML code so it works on both Netscape and IE cleanly
// as it appeared to only work under IE as written. Stylesheets still
// need work for Netscape but work under IE
//
// Version 1.3 - 12/15/01 (Jeremy.Bouse@UnderGrid.net)
// - Added a mechanic for including a caption file or use a default
// caption comment under pictures. Done through include() function so
// caption file can also include any HTML or even php code.
//
// Version 1.4 - 01/29/02 (Jeremy.Bouse@UnderGrid.net)
// - Cleaned up bug with thumbnails not showing properly past the first
// page as was reported to me.
// - Added code to link number of page links per row to make easier to
// read. Controlled by $pgperrow configuration declaration.
// Version 1.5 - 01/17/03 (wu@e-shell.org)
// - Adapted $ind to work with register_globals=off (default since
// php-4.2.0), so $ind is now $_GET['ind']
// Version 1.6 - 04/30/03 (lajgaard@mail.dk)
// - I have added four new variables. You can now deside what the
// maximum sizes of you large pictures and thumbnails should be.
// - the images are now resized to maintain ratio. The thumbnails
// are no longer the same size. But you can see what i the picture
// actually contains.
// Version 1.7 - 07/19/03 (edman007x@mac.com)
// - it is now XHTML 1.0 compliant
// - i have added a new varible (scale) to decide if you want to scale
// the pictures that do not excede the max width/height variable
// - fixed a bug where images that were wider than tall could exceed
// the max height varible and images that were taller than wide could
// exceed the max width variable
// Version 1.8 09/23/03 (edman007x@mac.com)
// - fixed all the $PHP_SELF varibles to $_SERVER['PHP_SELF'] and
// allowed people to specifiy it if PHP_SELF dosen't work($this_page)
// - fixed a typo in the thumbnail resizing(was $newheight, should be $newthumbh)
// - added default style style sheet to html output so you don't have to make a
// style sheet if you use the default(you can still use one if you want to)
//
//
//
//
//
//
//
// AUTHOR:
// Jo Demol (de_paashaas@yahoo.com)
//
// DESCRIPTION:
// Drop this file in any directory that you want and it automaticaly generates
// an easy to use browsable interface for your images
//
// RETURNED VARIABLES:
// no variables are returned
//
// Configuration Variables
// ======================
//
// scale : weather or not to scale the large img to the max height/width if it
// does not exceed the max height/width limits
// 0=don't scale 1=scale
// maxwidth : the maximum allowed width of the large picture
// maxheight : the maximum allowed height of the large picture
// thumbmaxw : the maximum allowed width of the thumbnail
// thumbmaxh : the maximum allowed height of the thumbnail
// imgperpage : the number of thumbnail images displayed
// its best to give this a value that is a multiple of imgperrow
// imgperrow : the number of thumbnail images per row
// pgperrow : the number of page links per row
// typelist : array that contains the imagetypes shown by the browser
// currentdir : default the directory where this php file resides,
// can be replaced by any directory of your choice
// title : enter the title of your page here
// home : enter path to your home directory or any other desired directory
// (where the home link goes to)
// this_page : the name of this file, $_SERVER['PHP_SELF'] should work, but if it dosen't
// just use the file name; this is where all the links to this page go
// captionext : filename extension placed on caption file with same name
// as image. (ie - <image>.<ext>.<captionext>)
// example: image file sunrise.jpg would use the caption
// file sunrise.jpg.txt with the default captionext
// caption : default caption to place under files if no caption file
// exists
// stylesheet : enter the path to your stylesheet here
// you may enter just '' to use the default(will embed it in the html)
// you may also enter 'none' to have no style sheet
// the stylesheet should have these classes:
//
// .imag { border-style : solid;
// border-color: blue;
// border-width : 1px;}
// .thumb { border-style : solid;
// border-color: #999999;
// border-width : 2px;}
// A:link { color: #999999;
// text-decoration : none; }
// A:visited { color: #999999;
// text-decoration : none; }
// A:hover { color:blue; }
// any of these classses can be adjusted to your needs
//
//
// USAGE:
// to browse through the images use the back and forward images
// click on one of the thumbnails
// or use one of the pagelinks to go directly to another set of images
// clicking on the large image will give you the full image
/////////////////////////////////////////////////////////////////////////////////////////////////////////


//---Variables---

$scale = 0;
$maxwidth = 550;
$maxheight = 430;
$thumbmaxw = 120;
$thumbmaxh = 90;
$imgperpage = 10;
$imgperrow = 3;
$pgperrow = 10;
$currentdir = getcwd ();
$typelist = array("jpg","jpeg","gif","png","JPG");
$imagelist = array();
$title = "Fotoreportaż";
$stylesheet = '' ;
$home = "{$_SERVER['PHP_SELF']}";
$this_page = "{$_SERVER['PHP_SELF']}";
$caption = "";
$captionext = "txt";

//--- ind is put to zero when the script is first called uppon---

if(!isset($_GET['ind']))
$_GET['ind'] = 0;
$index = $_GET['ind'];

//---the following code iterates through the directory and puts any image found in the imagelist array---

$dp=opendir($currentdir);
while ( false != ( $file=readdir($dp) ) ) {
if (is_file($file) && $file!="." && $file!=".."){

$extention = explode(".",$file);
$extfield = count($extention)-1;
$extention = $extention[$extfield];

if( in_array($extention,$typelist) ){
array_push ($imagelist,$file);
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">




<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>


<title><?= $title ?></title>
<?
if ($stylesheet == ''){
//--insert the default style sheet into html if none specified
echo '<style type="text/css">'
.'.imag { border-style : solid;'
.'border-color: blue;'
.'border-width : 1px;}'
.'.thumb { border-style : solid;'
.'border-color: #999999;'
.'border-width : 2px;}'
.'A:link { color: #999999;'
.'text-decoration : none; }'
.'A:visited { color: #999999;'
.'text-decoration : none; }'
.'A:hover { color:blue; }'
.'</style>';
} elseif ($stylesheet == 'none') {
//--no style sheet if that is what you want
} else {
echo "<link rel="STYLESHEET" href="$stylesheet" />";
}
?>
</head>
<body>

<table align="center" border="0">
<tr>
<td>
<? if($index-1 >= 0) {?>
<a href='<?= $this_page ?>?ind=<?= $index-1 ?>'>[ prev ]</a>
<? } ?>
</td>
<td>
<?

//--- This is where the large pictures are resized so that they maintain ratio---

$sizeee = getimagesize ("$imagelist[$index]");
$imgwidth = $sizeee[0];
$imgheight = $sizeee[1];

if ($scale == 1 || $imgwidth > $maxwidth || $imgheight > $maxheight) { // decide if img needs to be scaled
$newwidth = $imgwidth/($imgheight/$maxheight);
$newheight = $imgheight/($imgwidth/$maxwidth);
if ($imgwidth < $imgheight) {




if ($newwidth > $maxwidth)

{

?>
<a href="<?= $imagelist[$index] ?>" target="_blank">
<img src="<?= $imagelist[$index] ?>" width="<?= $maxwidth ?>" height="<?= $newheight ?>" alt="" />
</a>
<?
} else {

?>
<a href="<?= $imagelist[$index] ?>" target="_blank">
<img src="<?= $imagelist[$index] ?>" width="<?= $newwidth ?>" height="<?= $maxheight ?>" alt="" />
</a>
<?
}
} else {


if ($newhight > $maxheight)

{

?>
<a href="<?= $imagelist[$index] ?>" target="_blank">
<img src="<?= $imagelist[$index] ?>" width="<?= $newwidth ?>" height="<?= $maxheight ?>" alt="" />
</a>
<?
} else {


?>

<a href="<?= $imagelist[$index] ?>" target="_blank">
<img src="<?= $imagelist[$index] ?>" width="<?= $maxwidth ?>" height="<?= $newheight ?>" alt="" />
</a>

<?



}
}
} else { ?>
<a href="<?= $imagelist[$index] ?>" target="_blank">
<img src="<?= $imagelist[$index] ?>" width="<?= $imgwidth ?>" height="<?= $imgheight ?>" alt="" />
</a>
<? }
?>
</td>
<td>
<? if($index+1 < count($imagelist) ) {?>
<a href="<?= $this_page ?>?ind=<?= $index+1 ?>">[ next ]</a>
<? } ?>
</td>
</tr>
<tr>
<td>
</td>
<td>
<center><?
if (file_exists ($imagelist[$index]. "." . $captionext) &&
is_file ($imagelist[$index]. "." . $captionext) &&
!is_dir ($imagelist[$index]. "." . $captionext))
include $imagelist[$index]. "." . $captionext;
else
echo $caption; ?>
</center>
</td>
<td>
</td>
</tr>
</table>

<table align="center">
<tr><td></td>
<?

//---this code generates the thumbnails based on the configuration settings---

$nrpages = ceil( count($imagelist)/$imgperpage );

for($j=0;$j<$nrpages;$j++)
{
if( $index >= ($j*$imgperpage) && ($index < (($j+1) * $imgperpage)) ) {
for($i=($j*$imgperpage);$i<(($j+1) * $imgperpage);$i++) {
if(($i%$imgperrow == 0) && ($i > 0)) { ?>
</tr>
<tr>
<? }
if($i <count($imagelist) ) {
$path = "$this_page?ind=".$i; ?>
<td>

<?



//--- This is where the thumbnails are resized so that they maintain ratio---


$sizeee = getimagesize ("$imagelist[$i]");
$imgwidth = $sizeee[0];
$imgheight = $sizeee[1];

$newthumbw = $imgwidth/($imgheight/$thumbmaxh);
$newthumbh = $imgheight/($imgwidth/$thumbmaxw);
if ($imgwidth < $imgheight) {




if ($newthumbw > $thumbmaxw)

{

?>
<a href="<?= $path ?>">
<img src="<?= $imagelist[$i] ?>" width="<?= $thumbmaxw ?>" height="<?= $newthumbh ?>" alt="" />
</a>
<?
} else {


?>
<a href="<?= $path ?>">
<img src="<?= $imagelist[$i] ?>" width="<?= $newthumbw ?>" height="<?= $thumbmaxh ?>" alt="" />
</a>
<?
}
} else {


if ($newthumbh > $thumbmaxh)

{

?>
<a href="<?= $path ?>">
<img src="<?= $imagelist[$i] ?>" width="<?= $newthumbw ?>" height="<?= $thumbmaxh ?>" />
</a>
<?
} else {


?>

<a href="<?= $path ?>">
<img src="<?= $imagelist[$i] ?>" width="<?= $thumbmaxw ?>" height="<?= $newthumbh ?>" alt="" />
</a>

<?



}
}
?>
</td>
<? }
}
}
}
?>
</tr>
</table>
<br />
<center>
<?
//---this code generates links based on the configuration settings---
//---only puts $pgperrow page links per row to make cleaner---

for($j=0;$j<$nrpages;$j++) {
if(($j%$pgperrow == 0) && ($j > 0)) { ?>
<br />
<? } ?>
<a href="<?= $this_page ?>?ind=<?= ($j*$imgperpage) ?>">[page <?= ($j+1) ?>]</a>
<? } ?>
</center>
<center><a href="<?= $home ?>">[ home ]</a></center>
</body>
</html>
</body>
</html>
?>[/php:1:16de3b2c9d]

Czy moze mi ktos pomoc, bym mogl includowac galerie za pomoca linku, ktory napisalem wyzej, tak by wszystko dzialalo?
jerrys
Nie wiem czy to zadziała ale z tego co chyba gdzies kiedys czytalem to chyba warto sprobowac funkcji require zamiast include poniewaz ona chyba nie dziala w wywolaniach if ( zobacz pierwszy listing ktory zamiesciles) np: require('includes/mojabaza.php');
Nie wiem czy to pomoze ale moze sie udac smile.gif powodzenia.
kpjeziorak
jest maly problem, w/w skrypty nie sa mojego autorstwa, ja jestem zielony w php i kompletnie nic nie rozumiem co mi jerrys napisales sad.gif

EDIT: Poza tym wydaje mi sie, ze cos z tym jest nie tak, powinno pokazac inna sciezke do katalogu gdzie sa foty:
[php:1:64be730cbb]<?php
$home = "{$_SERVER['PHP_SELF']}";
$this_page = "{$_SERVER['PHP_SELF']}";
?>[/php:1:64be730cbb]
jerrys
Sproboj tego

echo "<a href='".basename($PHP_SELF).">costam"</a>";


A i mozesz jeszcze na stale wpisac w zmiennej adres np $php="www.jasnet.pl";

i moze wtedy pojdzie
jerrys
Jest jeszcze jedna mozliwosc ze $PHP_SELF nie dziala prawidlowo i trzeba tam wpisac dokładny adres gdzie chcesz skierowac skrypt (cala sciezke).
kpjeziorak
Eh, nic nie wychodzi:(

Moze potrafi ktos z was napisac taki prosty skrypcik: Skrypt w katalogu, w ktorym sie znajduje szuka pliki .jpg, nastepnie robi ich miniatury np. 120x90 i wyswietla je na stronie powiedzmy 4 kolumny po 5 obrazkow, po kliknieciu na obrazek otwiera sie oryginal. Bede wdzieczny za takie cos:)
alchemic
plik ktory przeskanuje CI katalog i zrobi miniaturki:

[php:1:6437cb9d16]<?php
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> generator miniaturek </TITLE>
<BODY BGCOLOR="#FFFFFF">
<link rel="stylesheet" href="galeria.css">
<?php
if (!isset($dawaj)) {
?>
<div align="center">
<form name="pytanie" action="<?php $PHP_SELF ?>" method="post">
Podaj długość krótszego boku miniaturki:<br>
<input type="text" name="bok"><br>
Podaj stopień kompresji miniaturki w % (1-100):<br>
<input type="text" name="kompresja"><br>
<input type="checkbox" name="kwadratowe" value="tak">kwadratowe miniaturki<br>
<input type="radio" name="kadruj" value="tak" checked>robiac kwadratowe kadruj obraz<br>
<input type="radio" name="kadruj" value="nie">robiac kwadratowe zmiesc caly obraz<br>
<input type="submit" name="dawaj" value="generuj">
</form>
</div>
<?php }

if ((isset($dawaj)) && ($dawaj=="generuj"))
{

//if (ImageTypes() & IMG_PNG) {
// echo "PNG Support is enabled";
//}
//if (ImageTypes() & IMG_JPG) {
// echo "JPG Support is enabled";
//}

$dir = opendir("./");
while ($plik = readdir($dir)) {
if (is_file("./$plik") && eregi(".jpg",$plik) && !eregi("_t.jpg",$plik)) {
$fotos[] = $plik;
}
}
sort($fotos);
for ($i = 0; $i < count($fotos); $i++ )
{

$in_nazwa = $fotos[$i];


$in_image = ImageCreateFromJPEG($in_nazwa);
$in_szerokosc = ImageSX($in_image);
$in_wysokosc = ImageSY($in_image);

if($kwadratowe=="tak") {

$out_wysokosc=$bok;
$out_szerokosc=$bok;

$out_image=ImageCreatetruecolor($out_szerokosc,$out_wysokosc);
if($kadruj=='tak') {

if($in_szerokosc>$in_wysokosc)
{
$in_szerokosc=$in_wysokosc; }
elseif ($in_szerokosc<$in_wysokosc)
{
$in_wysokosc=$in_szerokosc; }
imagecopyresampled($out_image, $in_image, 0, 0, 0, 0, $out_szerokosc, $out_wysokosc, $in_szerokosc, $in_wysokosc);
}
else
{

if($in_szerokosc>$in_wysokosc)
{
$proporcja=$in_wysokosc/$in_szerokosc;
$nowy_krotszybok = $bok*$proporcja;
$nowy_y = (($bok-$nowy_krotszybok)/2);
$in_wysokosc=$in_szerokosc;
imagecopyresampled($out_image, $in_image, 0, $nowy_y, 0, 0, $out_szerokosc, $out_wysokosc, $in_szerokosc, $in_wysokosc);
}
elseif ($in_szerokosc<$in_wysokosc)
{
$proporcja=$in_szerokosc/$in_wysokosc;
$nowy_krotszybok = $bok*$proporcja;
$nowy_x = (($bok-$nowy_krotszybok)/2);
$in_szerokosc=$in_wysokosc;
imagecopyresampled($out_image, $in_image, $nowy_x, 0, 0, 0, $out_szerokosc, $out_wysokosc, $in_szerokosc, $in_wysokosc);
}





}
}
elseif ($in_szerokosc>$in_wysokosc)
{
$out_wysokosc=$bok;
$out_szerokosc=($in_szerokosc/$in_wysokosc)*$bok;
$out_image=ImageCreatetruecolor($out_szerokosc,$out_wysokosc);
imagecopyresampled($out_image, $in_image, 0, 0, 0, 0, $out_szerokosc, $out_wysokosc, $in_szerokosc, $in_wysokosc);
}
elseif ($in_szerokosc==$in_wysokosc)
{
$out_wysokosc=$bok;
$out_szerokosc=$bok;
$out_image=ImageCreatetruecolor($out_szerokosc,$out_wysokosc);
imagecopyresampled($out_image, $in_image, 0, 0, 0, 0, $out_szerokosc, $out_wysokosc, $in_szerokosc, $in_wysokosc);
}
elseif ($in_szerokosc<$in_wysokosc)
{
$out_szerokosc=$bok;
$out_wysokosc=($in_wysokosc/$in_szerokosc)*$bok;
$out_image=ImageCreatetruecolor($out_szerokosc,$out_wysokosc);

imagecopyresampled($out_image, $in_image, 0, 0, 0, 0, $out_szerokosc, $out_wysokosc, $in_szerokosc, $in_wysokosc);
}

$out_nazwa = substr($fotos[$i],0,-4) . "_t.jpg";

imagejpeg ($out_image, $out_nazwa ,$kompresja);
echo "<img src="$out_nazwa"> ";

}
echo "<br><br>Miniaturki wygenerowane<br><br>";
echo "<a href="../index.php">Obejrzyj index</a>";
}

?>

</BODY>
</HTML>



?>[/php:1:6437cb9d16]


i plik ktory Ci to wyswietli:

[php:1:6437cb9d16]
<?php

$tytul = " galeria";
$styl = "galeria.css"; // zrob sobie
$opis = "opis.txt";
$poprzednie = "poprzednie";
$nastepne = "następne";
$powrot = "powrót";
$homepage = "Strona główna";
$homelink = "http://twoja strona";

// koniec

$dir = opendir("./");
while ($plik = readdir($dir)) {
if (is_file("./$plik") && eregi(".jpg",$plik) && !eregi("_t.jpg",$plik)) {
$fotos[] = $plik;
}
}
sort($fotos);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<title><?php echo($tytul) ?></title>
</head>
<?php echo("<link rel="stylesheet" href="$styl">") ?>
<body>
<div align="center">
<h2><?php echo ($tytul) ?></h2>
<!-- <b>Zdjęć: <? print count($fotos); ?></b><br> -->
<?php if ($show=="") { ?>
<div class="opis"><?php if (file_exists("$opis")) include "$opis" ?></div>
<br>
<table align="center" cellspacing="0" cellpadding="2" border="0">
<tr>
<?
$licznik = 1;
while (list($key,$val) = each($fotos)) {
print "<td width=75><a href="$PHP_SELF?show=$key"><img src="".substr($val,0,-4)."_t.jpg" border="0"><br>".ucfirst(substr($val,0,-4))."</a></td>n";
if ($licznik > 4) {
$licznik = 0;
print "</tr><tr>";
}
$licznik += 1;
}
?>
</tr>
</table>
<br>
<br>
<?php echo ("<a href="$homelink">$homepage</a>") ?>
<?php } ?>
<?php if ($show!="") { ?>
<?php echo ("<img src="$fotos[$show]">") ?>
<?php
$prev = $show-1;
$next = $show+1;
?>
<br><br><br>
<div class="komentarz">
<?php
if (file_exists("$komentarze")) {
$komentarze = file("$komentarze");
echo($komentarze[$show]);
}
?>
</div>
<br>
<TABLE width="300">
<TR>
<TD align="left" width="50%"><?php if ($show>"0") echo("<a href="$PHP_SELF?show=$prev">$poprzednie</a>") ?></TD>
<TD align="right" width="50%"><?php if ($show!=(count($fotos)-1)) echo ("<a href="$PHP_SELF?show=$next">$nastepne</a>") ?></TD>
</TR>
<TR>
<TD colspan="2" align="center">
<?php echo ("<a href="$PHP_SELF">$powrot</a>&nbsp;&nbsp;<a href="$homelink">$homepage</a>") ?>
</TD>
<TD></TD>
</TR>
</TABLE>
<?php } ?>
</div>
</body>
</html>


?>[/php:1:6437cb9d16]
kpjeziorak
Dziekuje za pomoc, tylko mam jeszcze jedno pytanie:
Jak te dwa pliki maja sie nazywac i jak maja byc ze soba powiazane, bo przeciez jeden odpowiada za miniaturki a drugi za ich wyswietlenie, aha i jeszcze czy musze tworzyc plik: opis.txt - czy jezeli go nie bedzie to galeria tez bedzie dzialac?

[EDIT]: Przepraszam juz wiem o co chodzi... jednym generuje a drugim wyswietlam, czyli nazwa nie gra roli smile.gif , wszystko dziala tylko nie wiem czemu nie generuje mi miniatur, mam taki komunikat:
Cytat
Fatal error: Call to undefined function: imagecreatefromjpeg() in /home/jeziorak/public_html/poll/galeria/gen.php on line 49
alchemic
nazwy nie maja znaczenia ale plik ktory wyswietla daj np: index.php opis.txt nie musi byc...
Kod
Fatal error: Call to undefined function: imagecreatefromjpeg() in /home/jeziorak/public_html/poll/galeria/gen.php on line 49
a co to to nie wiem dlaczego to tak.... moze server czegos nie ma nie wiem...
kpjeziorak
dzieki, cos wymysle, na szczescie gdy sam stworze miniatury o nazwie "nazwa_miniatury_t.jpg" to sa wyswietlane, wiecej roboty, ale wazne ze dziala biggrin.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2024 Invision Power Services, Inc.