Mam skrypt galeria.php
<?php
function imgType($name)
{
if(substr($name, -4, 4) == '.jpg' || substr($name, -4, 4) == 'jpeg') {
return "IMAGETYPE_JPEG";
}
elseif(substr($name, -4, 4) == '.gif') {
return "IMAGETYPE_GIF";
}
elseif(substr($name, -4, 4) == '.png') {
return "IMAGETYPE_PNG";
}
}
function resizeImage($source, $max_x, $max_y, $save_image, $jpeg_quality = 100)
{
/*
* source - obrazek jpeg
* max_x - maksymalna szerokosc pomniejszonego obrazka
* max_y - maksymalna dlugosc pomniejszonego obrazka
* save_image - nazwa pliku do ktorego zostanie zapisany nowy obrazek
* jpeg_quality - jakosc powstalego obrazu jpeg - jezeli bedzie inny to argument jest nie wazny (domyslnie 100)
*/
if(imgType($source) == "IMAGETYPE_JPEG")
{
$img_src = imagecreatefromjpeg($source);
}
elseif(imgType($source) == "IMAGETYPE_GIF")
{
$img_src = imagecreatefromgif($source);
}
elseif(imgType($source) == "IMAGETYPE_PNG")
{
$img_src = imagecreatefrompng($source);
}
else
{
die('Wrong filetype! Accepted images: JPG/JPEG, GIF, PNG'); }
$image_x = imagesx($img_src);
$image_y = imagesy($img_src);
if($image_x > $image_y) // Landscape
{
$ratio_x = ($image_x > $max_x) ? $max_x/$image_x : 1;
$ratio_y = $ratio_x;
$move = 'y';
}
else // Portrait
{
$ratio_y = ($image_y > $max_y) ? $max_y/$image_y : 1;
$ratio_x = $ratio_y;
$move = 'x';
}
$new_x = $image_x*$ratio_x;
$new_y = $image_y*$ratio_y;
$move_x = ($move == "x") ? ($max_x-$new_x)/2 : 0;
$move_y = ($move == "y") ? ($max_y-$new_y)/2 : 0;
$new_img = imagecreatetruecolor($max_x, $max_y);
$background = imagecolorallocate($new_img, 255, 255, 255);
imagefill($new_img, 0, 0, $background);
imagecopyresampled($new_img, $img_src, $move_x, $move_y, 0, 0, $new_x, $new_y, $image_x, $image_y);
if(imgType($save_image) == "IMAGETYPE_JPEG")
{
imagejpeg($new_img, $save_image, 100);
}
elseif(imgType($save_image) == "IMAGETYPE_GIF")
{
imagegif($new_img, $save_image);
}
elseif(imgType($save_image) == "IMAGETYPE_PNG")
{
imagepng($new_img, $save_image);
}
echo '<img src="'.$save_image.'" border="0">'; }
function showFileSize( $size )
{
$sizes = array( 'B', 'kB', 'MB', 'GB', 'TB' ); $pos = 0;
while( $size >= 1024)
{
$size /= 1024;
$pos++;
}
return sprintf( '%.02f', $size ) . ' ' . $sizes[ $pos ]; }
$dir = './duze/'; // katalog z grafikami
$min = './mini/'; // katalog na miniaturki
$minW = 140; // szerokość miniaturki
$minH = 100; // wysokość miniaturki
$perLine = 4; // ilość grafik w linii
{
while( ( $file = readdir( $dh ) ) !== false ) {
{
if( !file_exists( $saveFile = $min . 'small_' . $file ) ) {
resizeImage( $dir . $file, $minW, $minH, $saveFile );
}
'size' => showFileSize
( filesize( $dir . $file ) ) );
}
}
}
?>
<style type="text/css">
body, td {
font: 12px Verdana;
text-align: center;
vertical-align: top;
white-space: nowrap;
}
img {
border: 0px;
}
</style>
<table>
<tr>
<?php
$num = 0;
foreach( $files as $fileName => $fileInfo )
{
if( ( $num % $perLine ) == 0 and ( $num > 0 ) )
{
?>
</tr>
<tr style="height: 5px;">
</tr>
<tr>
<?php
}
?>
<td>
<i><?= $fileName; ?></i><br/>
<a target="_BLANK" href="<?= $dir . $fileName; ?>"><img src="<?= $min . 'small_' . $fileName; ?>" alt=""/></a><br/>
Rozmiar: <b><?= $fileInfo[ 'size' ]; ?></b><br/>
Dodano: <b>
<?= date( 'd/m/Y', $fileInfo[ 'time' ] ); ?></b>
</td>
<?php
$num++;
}
?>
</tr>
</table>
Po nacisnieciu wyswietla w oddzielnym oknie obrazki . Adres to strona.pl/duze/obrazek.jpg
Odpowiada za to
<a target="_BLANK" href="<?= $dir . $fileName; ?>">
Jak przerobic owa linijkę bym otrzymał adrsowanie
<?php
index.php?page=obrazek&cat1=duze
// gdzie obrazek na nazwa od np obrazek.jpg , duze to nazwa katalogu, w ktorym gal
eria przechowuje duze obrazki, cat1 to moja zmienna, ktorej uzywam na stronie glo
wnej
?>
Na stronie index.php uzywam kodu :
<?php
$folPages = ''; // folder , w ktorym trzymasz te strony
$page = $_GET['page'];
if (isset($_GET['cat1'])) $kat=$_GET['cat1'].'/';
else
$kat='';
if (isset($_GET['cat2'])) $kat2=$_GET['cat2'].'/';
else
$kat2='';
$roz = array("php", "html", "php3", "inc", "htm", "txt", "jpg", "dat",); // itp. for($i=0;$i<count($roz);$i++)
{
$file=$folPages.$kat.$kat2.$page.'.'.$roz[$i];
include($file);
break;
} else {
if($i == (count($roz) - 1
)) { } } } } else {
include($folPages.'start.php');
}
?>