В общем, времени до полного ума доводить нету, но думаю, из того, что я накалякал, станет ясно, почему у тебя не шло. Я раскоментировал то, что мешало работе, всё у меня и создаётся, и показывается в указанной мною директории.
Код:
<?php
$columns = 5;
$thmb_width = 120;
$thmb_height = 80;
$mydir="./mojadirektorija/";
function resizeImage($originalImage,$toWidth,$toHeight){
// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$xscale=$width/$toWidth;
$yscale=$height/$toHeight;
// Recalculate new size with default ratio
if ($yscale>$xscale){
$new_width = round($width * (1/$yscale));
$new_height = round($height * (1/$yscale));
}
else {
$new_width = round($width * (1/$xscale));
$new_height = round($height * (1/$xscale));
}
// Resize the original image
$imageResized = imagecreatetruecolor($new_width, $new_height);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
return $imageResized;
}
function generateThumbnails(){
global $thmb_width,$thmb_height,$mydir;
// Open the actual directory
if ($handle = opendir($mydir)) {
while ($file = readdir($handle)) {
if (is_file($mydir.$file)){
if (strpos($file,'_th.jpg')){
$isThumb = true;
} else {
$isThumb = false;
}
if (!$isThumb) {
// Process the file string
//$dirName = substr($file,0,strpos($file,basename($mydir.$file)));
$dirName=$mydir;
//if (strlen($dirName) < 1) $dirName = '.';
//$fileName = basename($file);
$fileName=$file;
$fileMain = substr($fileName,0,strrpos($fileName,'.'));
$extName = substr($fileName,strrpos($fileName,'.'),
strlen($fileName)-strrpos($fileName,'.'));
// Check if the actual file is a jpeg image
if (($extName == '.jpg') || ($extName == '.jpeg') || ($extName == '.JPG')){
$thmbFile = $dirName.'/'.$fileMain.'_th.jpg';
// If a thumbnail dosn't exists tahn create a new one
if (!file_exists($thmbFile)){
$aaa=resizeImage($mydir.$file,$thmb_width,$thmb_height);
imagejpeg($aaa,$thmbFile,80);
}
}
}
}
}
}
}
function getNormalImage($file){
$base = substr($file,0,strrpos($file,'_th.jpg'));
if (file_exists($base.'.jpg')) return $base.'.jpg';
elseif (file_exists($base.'.jpeg')) return $base.'.jpeg';
elseif (file_exists($base.'.JPG')) return $base.'.JPG';
else return "";
}
function displayPhotos(){
global $columns,$mydir;
generateThumbnails();
$act = 0;
// Open the actual directory
if ($handle = opendir($mydir)) {
// Read all file from the actual directory
while ($file = readdir($handle)) {
$files[] = $mydir.$file;
}
//Close directories and sort files in a decending order
closedir($handle);
sort($files);
reset($files);
foreach ($files as $k => $file) {
if ($file != $mydir."." && $file != $mydir.".." && $file != $mydir."index.php~" && $file != $mydir."index.php" ) {
$com = getNormalImage($file).'.html';
// Check whether tha actual item is a valid file
if (is_file($file)){
// Check whether the actual image is a thumbnail
if (strpos($file,'_th.jpg')){
++$act;
if ($act > $columns) {
echo '</tr><tr><td class="photo"><A HREF="showpic.php?kep='.getNormalImage($file).'" onClick="return popup(this, \'stevie\')"><img src="'.$file.'" alt="'.$file.'"/></A><br><a href="'.$com.'" target=\"_blank\">komment</a></td>';
$act = 1;
} else {
echo '<td class="photo"><A HREF="showpic.php?kep='.getNormalImage($file).'" onClick="return popup(this, \'stevie\')"><img src="'.$file.'" alt="'.$file.'"/></A><br><a href="'.$com.'" target=\"_blank\">komment</a></td>';
}
}
}
}
}
}}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<table width="100%" border="0">
<tr>
<?php displayPhotos(); ?>
</tr>
</table>
</body>