<?php
$server=getenv("HTTP_REFERER");
define ("MAX_SIZE","10000");
define ("WIDTH","42");
define ("HEIGHT","30");
function make_thumb($img_name,$filename,$new_w,$new_h)
{
$ext=getExtension($img_name);
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);
if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);
if(!strcmp("gif",$ext))
$src_img=imagecreatefromgif($img_name);
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if($ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if(!strcmp("png",$ext))
imagepng($dst_img,$filename);
else
imagejpeg($dst_img,$filename);
imagedestroy($dst_img);
imagedestroy($src_img);
}
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
if(isset($_POST['Submit']))
{
$image=$_FILES['image']['name'];
if ($image)
{
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
echo '<h1>Неизвестно разширение!</h1>';
$errors=1;
}
else
{
$size=getimagesize($_FILES['image']['tmp_name']);
$sizekb=filesize($_FILES['image']['tmp_name']);
if ($sizekb > MAX_SIZE*10240)
{
echo '<h1>Надвишен е лимитът за размер!</h1>';
$errors=1;
}
$image_name=time().'.'.$extension;
$newname="gallery/images/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Копирането не е успешно!</h1>';
$errors=1;
}
else
{
$thumb_name="gallery/thumb/".$image_name;
$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
}} }}
if(isset($_POST['Submit']) && !$errors)
{
echo '<div align="center">';
echo "<h1>Снимката е качена успешно!</h1>";
echo '<br>';
echo '<br>';
echo '<table>';
echo '</table>';
echo '</div>';
}
$opisanie = $_POST['opisanie'];
$file = "gallery.xml";
$s='';
if(file_exists($file))
{
$fp = fopen($file, 'r');
while(!feof($fp))
{
$s.=fgets($fp);
}
$s=str_replace("</pictures>","",$s);
}
else $s="<pictures>\n";
if(strpos($s,"<pictures>")===FALSE) $s="<pictures>\n".$s;
$s.="<photo>\n\t<imageName>gallery/images/" . $image_name . "</imageName>\n\t<thumbName>gallery/thumb/" . $image_name . "</thumbName>\n\t<description>" . $opisanie . "</description>\n</photo>\n";
$s.="</pictures>";
$fp = fopen($file, 'w');
fwrite($fp, $s);
fclose($fp);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Влачи</title>
<style type="text/css">
body
{
background: #F9F9F7 url('img/a1.gif') repeat-x;
font-size: 11px;
font-family: "trebuchet ms", helvetica, sans-serif;
color: #8C8C73;
line-height: 18px;
}
input {
color: #000;
text-decoration: none;
background: #F4F3F3;
border: 1px solid #ADAEAF;
font: normal 9pt verdana, arial;
}
input:hover {
background: #F4F3F3;
border: 1px solid #000;
}
</style>
</head>
<body>
<div align="center">
<br>
Разрешени разширения: jpg, jpeg, gif и png...
<br>
<form class=input name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr>
<td><input class=input type="file" name="image" ></td>
<td>Описание: <input class=input type="text" name="opisanie"></td>
<td><input class=input name="Submit" type="submit" value="Качи"></td>
</tr>
</table>
</form>
</div>
</body>
</html>