";
$uploaddir = "./$photo_folder/$folder/";
if (chdir("$uploaddir")) {
} else {
echo "
Please create the directory first
";
exit;
}
$dir = opendir(".");
foreach($userfile as $tagname=>$object) {
echo "$tagname = $object
";
if ($object) {
// get the temporary name (e.g. /tmp/php34634.tmp)
$tempName = $_FILES['userfile']['tmp_name'][$tagname];
// get the real filename
$realName = $_FILES['userfile']['name'][$tagname];
// where to save the file?
$target = $realName;
// print something to the user
echo "
Processing file $realName...\n";
flush();
// move the file to the target directory
move_uploaded_file($tempName,$target);
// Spectial File Processing
$file = $realName;
createthumb("$file","tn_".$file,135,135);
$watermark = "../../watermark.png";
$quality = "75";
createthumb("$file",$file,500,500);
if ($watermark_option == "yes") {
watermark($file, $file, $watermark, $quality);
}
$queryb="SELECT * FROM `$event_id` WHERE image='$file'";
$resultb=mysql_query($queryb);
$numb=mysql_num_rows($resultb);
if ($numb) {
echo "Image Replaced
";
} else {
$query = mysql_query("INSERT INTO `$event_id` ( `folder`, `image`, `image_cat`)
VALUES ('$folder', '$file', '$image_category');")
or die (mysql_error());
echo "Image Added
";
}
echo "next file...
";
flush();
}
flush();
}
}
?>
//$filename should be a JPG and $watermark a PNG-24 with alpha transparency. $quality is 1-100 JPG quality on output.
// Puts a watermark on the Image
function watermark($srcfilename, $newname, $watermark, $quality) {
$imageInfo = getimagesize($srcfilename);
$width = $imageInfo[0];
$height = $imageInfo[1];
$logoinfo = getimagesize($watermark);
$logowidth = $logoinfo[0];
$logoheight = $logoinfo[1];
$horizextra =$width - $logowidth;
$vertextra =$height - $logoheight;
$horizmargin = round($horizextra / 2);
$vertmargin = round($vertextra / 2);
$photoImage = ImageCreateFromJPEG($srcfilename);
ImageAlphaBlending($photoImage, true);
$logoImage = ImageCreateFromPNG($watermark);
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
ImageCopy($photoImage, $logoImage, 90, 50, 0, 0, $logoW, $logoH);
//ImageJPEG($photoImage); // output to browser
ImageJPEG($photoImage,$newname, $quality);
ImageDestroy($photoImage);
ImageDestroy($logoImage);
}
// Creates Thumbnail Image
function createthumb($name,$filename,$new_w,$new_h){
global $gd2;
$system=explode(".",$name);
if (preg_match("/jpg|jpeg|JPG|JPEG/",$system[1])){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match("/png/",$system[1])){
$src_img=imagecreatefrompng($name);
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$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 (preg_match("/png/",$system[1])){
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
?>