Location: PHPKode > projects > PHP Enter > www/admin/addimage.php
<?php include('header.php'); include('options.php'); ?>
<?php
if(isset($_POST['query'])){
$repath = $config['repath'];
$current_image=$_FILES['image']['name'];
$extension = substr(strrchr($current_image, '.'), 1);
$time = date("fYhis");
$gtitle = $_POST['gtitle'];
$amess = $_POST['amess'];
if (ereg("^\.",$amess)) {
echo "<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";  
 Die();
}
if (ereg("\javascript", $amess)) {
echo "<center>Invalid Characters: <font color = \"red\"><strong>javascript</strong></font> <a href=\"javascript:history.go(-1)\">Go Back</a></center>";  
 Die();
}
if (strlen($amess) < 3) {
echo "<center>Field must be at least 3 characters long:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";  
 Die();
}
if (strlen($amess) > 520) {
echo "<center>Max Characters Field: 520
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";  
 Die();
}
if (get_magic_quotes_gpc()) {
$amess = addslashes($amess);
}
$amess = mysql_real_escape_string($amess);
$current_image=$_FILES['image']['name'];
$extension = substr(strrchr($current_image, '.'), 1);
if (($extension!= "jpg") && ($extension != "jpeg")) 
{
die('Please Upload Valid JPG File');
}
$time = date("fYhis");
$new_image = $time . "." . $extension;
$destination= $repath . '/uploads/' . $new_image;
$action = copy($_FILES['image']['tmp_name'], $destination);
function ccthumb($imgSrc,$filename,$thumbnail_width,$thumbnail_height) {
list($width_orig, $height_orig) = getimagesize($imgSrc);   
if ($width_orig > 940 || $height_orig > 940)
{
echo "<br>Maximum width and height exceeded. Please upload images below  780 x 780 px size";
exit();
}
$tag=explode('.',$imgSrc); 
if (preg_match('/jpg|jpeg/',$tag[1])){
if (@$cimage = imagecreatefromjpeg($imgSrc) == true){
$cimage = imagecreatefromjpeg($imgSrc);
}else{
die("wrong file");
}}
$ratio_orig = $width_orig/$height_orig;
if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
$new_height = $thumbnail_width/$ratio_orig;
$new_width = $thumbnail_width;
} else {
$new_width = $thumbnail_height*$ratio_orig;
$new_height = $thumbnail_height;
}
$x_mid = $new_width/2;  //horizontal middle
$y_mid = $new_height/2; //vertical middle
$process = imagecreatetruecolor(round($new_width), round($new_height)); 
imagecopyresampled($process, $cimage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
$thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height); 
imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
imagejpeg($thumb,$filename,100); 
return $thumb;
}
ccthumb($destination, $repath . '/maxthumb/' . $new_image,270,250);
ccthumb($destination, $repath . '/minthumb/' . $new_image,144,82);
$result = mysql_query("INSERT INTO vgalery (guniver,gtitle,gdate,gamess) 
VALUES ('$new_image','$gtitle',NOW(),'$amess')")
or die(mysql_error());
echo 'Successfully!';
}else{
$univer = date("fYhis");
?>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="8" bgcolor="#FFFFFF">
<tr><td><strong>Gallery</strong></td><tr>
<tr><td width="450px">
<div id=vforms>
<form action="addimage.php" enctype="multipart/form-data" method="post">
Title:
<br />
<input type="text" name="gtitle" size="35">
<br />
<br />
Image:(only jpg formats);
<br />
<input type="file" name="image">
<br />
<br />
Description:
<br />
<textarea name="amess" style="width:627px;height:244px;"></textarea><br /><br />
<br />
<input class="incc" type="submit" value="Submit" name="query" style="color:#555;border:1px solid #ccc;background:#f8f8f8">
</form>
</td></tr></table>
<?php
}
?>


  
Return current item: PHP Enter