Една проста галериика

jooorooo

Registered
ето ви една проста галерия :-) писах я скоро ей така за трепане на времето.

Код:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html >
 <head>
 <title>galleria</title>
 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251">
 <style type="text/css"> 
#konteiner 
{ 
width: 820px; 
background: #FFF8F0;
} 
.div{ 
width:200px; 
height:200px; 
float:left; 
} 
</style>
 </head>
 <body>
 <center><a href="?act=up">add file</a></center><br/>
 <div id="konteiner">
<?php
//config file
$img_folder = "./images"; 
$maxw="190";
$maxh="170";
//config file
//function size img
function razmer_kartinka($img,$maxw,$maxh)
{
list($width,$height) = @getimagesize($img); 
if($width>$maxw)
{
$neww=$maxw;
$newh=$height/($width/$maxw);
}
elseif($height>$maxh)
{
$newh=$maxh;
$neww=$width/($height/$maxh);
}
elseif(($width<=$maxw) AND ($height<=$maxh))
{
$newh=$height;
$neww=$width;
}
return "<img src='".$img."' width='".$neww."' height='".$newh."'>";
}
//function size img
//function extension
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
//function extension
$act=$_GET['act'];
if($act=="up")
	{
	echo "<form action='' method='post' name='form' enctype=\"multipart/form-data\">
	<input name='ufile' type=\"file\" id='ufile' size=\"50\" /><br/>
	<input type='submit' name='Submit' value='Качване'>
	</form>";
	if($_POST['Submit'])
		{
	if($_FILES['ufile']['name'] !="") 
		{
		$ext=getExtension($_FILES['ufile']['name']);
		if(($ext=='jpg') OR ($ext=='jpeg') OR ($ext=='gif') OR ($ext=='png') OR ($ext=='JPG') OR ($ext=='JPEG') OR ($ext=='GIF') OR ($ext=='PNG'))
			{
		$im_name=time().".".$ext;
		$ok=copy($_FILES['ufile']['tmp_name'],$img_folder."/".$im_name) or die('error 1');
			}
		}
	if($ok)
		{
		echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=gallery.php\">";
		}
		else
		{
		echo "ne staa";
		}
		}
	}
elseif($act=="del")
	{
	$file=$_GET['file'];
	$ok=@unlink($img_folder."/".$file); 
	if($ok)
		{
		echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=gallery.php\">";
		}
	}
else
	{
	$dh = opendir($img_folder); 
	while($item = readdir($dh)) 
		{ 
		if($item != "." and $item != "..") 
			{ 
			if(is_dir($dir.$item)) 
				{
				}
				else
				{ 
				print "<div class='div' align='center'>".razmer_kartinka($img_folder."/".$item,$maxw,$maxh)."<br><a href='?act=del&file=".$item."'>[Изтрии]</a></div>"; 
				} 
			} 
		} 
	}
?>
</div>
</body>
</html>

ето и демо

http://webjo.no-ip.org/110907/gallery.php
 
излезе v.2.0
допълнения:
1. показва width и height под картинката, както и размера на картинката
2. добавед е дизайн.
3. картинките се отварят в popup прозорец

Код:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<title>galleria</title> 
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251"> 
<title>Галерия</title>
<style type="text/css"> 
body
{
	background: #CC0000; 
}
#konteiner 
{ 
	width: 820px; 
	background: #FFF8F0; 
}  
.div{ 
	width:200px; 
	height:200px; 
	float:left; 
	border:2px solid #CC0000;
	margin:2px;
} 
.imginfo
{
color: #00008B; 
text-decoration: none; 
font-size: 10; 
font-family: Arial, Helvetica, sans-serif; 
}
A:LINK
{
color: #00008B; 
text-decoration: none; 
font-size: x-small; 
font-family: Arial, Helvetica, sans-serif;
} 
A:Visited
{color: #00008B; 
text-decoration: none; 
font-size: x-small; 
font-family: Arial, Helvetica, sans-serif;
} 
A:Hover
{color: #00008B; 
text-decoration: underline; 
font-size: x-small; 
font-family: Arial, Helvetica, sans-serif;
}
</style> 
<script type="text/javascript">
PositionX = 100;
PositionY = 100;
defaultWidth  = 200;
defaultHeight = 200;
var AutoClose = true;

if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<img name="'+imageTitle+'" src='+imageURL+' style="display:block"></body></html>');
close();		
}}

</script>
 </head> 
 <body> 
 <center><a href="?act=up">add file</a></center><br/> 
 <center>
 <div id="konteiner"> 
<?php 
//config file 
$img_folder = "./images"; 
$maxw="190"; 
$maxh="170"; 
//config file 
//function size img 
function razmer_kartinka($img,$maxw,$maxh) 
{ 
list($width,$height) = @getimagesize($img); 
if($width>$maxw) 
{ 
$neww=$maxw; 
$newh=$height/($width/$maxw); 
} 
elseif($height>$maxh) 
{ 
$newh=$maxh; 
$neww=$width/($height/$maxh); 
} 
elseif(($width<=$maxw) AND ($height<=$maxh)) 
{ 
$newh=$height; 
$neww=$width; 
} 
return "<a href=\"javascript:popImage('".$img."','".$img."')\"><img src='".$img."' width='".$neww."' height='".$newh."' alt='".$img."' border='0'></a>"; 
} 
//function size img 
//function extension 
function getExtension($str) { 
$i = strrpos($str,"."); 
if (!$i) { return ""; } 
$l = strlen($str) - $i; 
$ext = substr($str,$i+1,$l); 
return $ext; 
} 
//function extension 
//function extension 
function imagesize($str) { 
$size = filesize($str); 
$i=0; 
$iec = array("K", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"); 
while (($size/1024)>1) { 
$size=$size/1024; 
$i++; 
} 
list($width,$height) = @getimagesize($str);
return "Width: ".$width."px Height: ".$height."px<br>Размер: ".substr($size,0,strpos($size,'.')+3)." ".$iec[$i]; 
} 
//function extension 
$act=$_GET['act']; 
if($act=="up") 
   { 
   echo "<form action='' method='post' name='form' enctype=\"multipart/form-data\"> 
   <input name='ufile' type=\"file\" id='ufile' size=\"50\" /><br/> 
   <input type='submit' name='Submit' value='Качване'> 
   </form>"; 
   if($_POST['Submit']) 
      { 
   if($_FILES['ufile']['name'] !="") 
      { 
      $ext=getExtension($_FILES['ufile']['name']); 
      if(($ext=='jpg') OR ($ext=='jpeg') OR ($ext=='gif') OR ($ext=='png') OR ($ext=='JPG') OR ($ext=='JPEG') OR ($ext=='GIF') OR ($ext=='PNG')) 
         { 
      $im_name=time().".".$ext; 
      $ok=copy($_FILES['ufile']['tmp_name'],$img_folder."/".$im_name) or die('error 1'); 
         } 
      } 
   if($ok) 
      { 
      echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=galeria.php\">"; 
      } 
      else 
      { 
      echo "Картинката не беше качена."; 
      } 
      } 
   } 
elseif($act=="del") 
   { 
   $file=$_GET['file']; 
   $ok=@unlink($img_folder."/".$file); 
   if($ok) 
      { 
      echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=galeria.php\">"; 
      } 
   } 
else 
   { 
   $dh = opendir($img_folder); 
   while($item = readdir($dh)) 
      { 
      if($item != "." and $item != "..") 
         { 
         if(is_dir($dir.$item)) 
            { 
            } 
            else 
            { 
            print "<div class='div'><table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" align=\"center\">".razmer_kartinka($img_folder."/".$item,$maxw,$maxh)."</td></tr><tr><td height=\"25\" valign=\"top\" align=\"center\" class=\"imginfo\">".imagesize($img_folder."/".$item)."</td></tr><tr><td height=\"22\" align=\"center\"><a href='?act=del&file=".$item."'>[Изтрии]</a></td></tr></table></div>"; 
            } 
         } 
      } 
   } 
?> 
</div> 
</center>
</body> 
</html>
 
StormBreaker каза:
Ъммм видяхте ли от кога е темата? Точно преди 1 година и 2 дни е последния пост.

Съжелявам не обърнах внимание просто ровех из темите за нещо полезно и... сри
 

Back
Горе