ето ви една проста галерия
писах я скоро ей така за трепане на времето.
ето и демо
http://webjo.no-ip.org/110907/gallery.php
Код:
<!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