<? /// ...puti k papkam ystanovleni vishe... pole file - pod imenem file2
/// proverka na tip faila
if ($file2 == "none" || $file2 == "") {echo "You didn't choose file!"; exit;} // ne vibran
if ($file2_size > $max_size) {echo "$file2_name is too big."; exit;} // bol'shoy
if (($file2 != "none" || $file2 != "") && (($file2_type != "image/pjpeg") && ($file2_type != "image/gif")))
{echo "$file2_name ($file2_type) has invalid type."; exit;} // ne tot tip
else {
//=============================================
function date_to_timestamp($dt) {
$yr=strval(substr($dt,6,4));
$mo=strval(substr($dt,3,2));
$da=strval(substr($dt,0,2));
$hr=strval(substr($dt,0,0));
$mi=strval(substr($dt,0,0));
$se=strval(substr($dt,0,0));
return mktime($hr,$mi,$se,$mo,$da,$yr);
}
if(ereg("left", $kefal) == True) { $menu = "left"; $kefal = substr($kefal, 4);}
$sql = "INSERT INTO photos VALUES (
Null,
'".$lang."',
".$kefal.",
'".$photo_order."',
'".$file2_name."',
'".$phot_descr."',
".date_to_timestamp($date_create).",
".date_to_timestamp($exp_date).",
'',
'".$active."')";
// run SQL
$result = mysql_query($sql) or die(mysql_error());
}
if (!$result) {
// esli ne zanesli v bazu
print "<script>window.location.href='add_photos.php?message=Cannot add photo!'</script>";}
else {
// esli zanesli,gruzim file
//copy ("$file2_tmp_name", "$path/$file2_name");
//////// resize and create thimbs
$size=getimagesize($_FILES['file2']['tmp_name']);
if ($size[0]>=$size[1])
{
$size0=250;
$size1=250/$size[0]*$size[1];
$size2=90;
$size3=90/$size[0]*$size[1];
}
else
{
$size1=250;
$size0=250/$size[1]*$size[0];
$size3=90;
$size2=90/$size[1]*$size[0];
}
$src_img=imagecreatefromjpeg($_FILES['file2']['tmp_name']);
$dst_img=imagecreatetruecolor($size0, $size1);
$dst_img1=imagecreatetruecolor($size2, $size3);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $size0, $size1, $size[0], $size[1]);
imagecopyresampled($dst_img1, $src_img, 0, 0, 0, 0, $size2, $size3, $size[0], $size[1]);
imagejpeg($dst_img, "../photos/".$_FILES['file2']['name'], 90);
imagejpeg($dst_img1, "../photos/s_".$_FILES['file2']['name'], 99);
imagedestroy($src_img);
imagedestroy($dst_img);
imagedestroy($dst_img1);
move_uploaded_file($_FILES['file2']['tmp_name'],"$path/$file2_name");
}
?>
|