query($sql); } if(isset($_POST['img_do'])) { foreach($_FILES as $k=>$v) { if(substr($k,0,8) == "img_file") { $fileNr = substr($k,8); $title = $_POST['img_title'.$fileNr]; $filename = $_FILES['img_file'.$fileNr]['name']; $tmpfile = $_FILES['img_file'.$fileNr]['tmp_name']; $filetype = strrchr($filename,"."); if($filetype = ".jpg") { $im = imagecreatefromjpeg($tmpfile); } elseif($filetype = ".png") { $im = imagecreatefrompng($tmpfile); } elseif($filetype = ".gif") { $im = imagecreatefromgif($tmpfile); } if(!$im) { $error = "Filtypen er ikke godkjent."; } else { /* find names for the files */ $orgin = "orgin_".substr(md5(time()),5,4)."_".substr($filename,0,strlen($filename)-strlen($filetype)).".jpg"; $middle = "middle_".substr(md5(time()),5,4)."_".substr($filename,0,strlen($filename)-strlen($filetype)).".jpg"; $thumb = "thumb_".substr(md5(time()),5,4)."_".substr($filename,0,strlen($filename)-strlen($filetype)).".jpg"; /* insert to database */ $sql = "INSERT INTO omg_galleryImages(category_id, image, orginal, thumb, title,date) VALUES('$gId', '$middle', '$orgin','$thumb','$title',NOW())"; $db->query($sql); /* save orginal */ move_uploaded_file($tmpfile,$orgin); /* find sizes */ $orginWidth = imagesx($im); $orginHeight = imagesy($im); /* find size for middle */ $newWidth = 750; $ar = $newWidth / $orginWidth; $newHeight = $orginHeight * $ar; if($newHeight > $newWidth) { $newHeight = 750; $ar = $newHeight / $orginHeight; $newWidth = $orginWidth * $ar; } $midIm = imagecreatetruecolor($newWidth,$newHeight); imagecopyresampled($midIm,$im,0,0,0,0,$newWidth,$newHeight,$orginWidth,$orginHeight); /* save middle image */ imagejpeg($midIm, "gfx/gallery/".$middle,100); imagedestroy($im); /* try to create the thumb */ $newWidth = 135; $ar = $newWidth / $orginWidth; $newHeight = $orginHeight * $ar; if($newHeight > 105) { $newHeight = 105; $ar = $newHeight / $orginHeight; $newWidth = $orginWidth * $ar; } $thumbIm = imagecreatetruecolor($newWidth,$newHeight); imagecopyresampled($thumbIm,$im,0,0,0,0,$newWidth,$newHeight,$orginWidth,$orginHeight); imagejpeg($thumbIm,"gfx/gallery/".$thumb,100); imagedestroy($thumbIm); } } } header("Location: index.php?mod=galleryAdminCategory&gallery=$gId"); die(); } $sql = "SELECT category FROM omg_galleryCategories WHERE id='$gId' LIMIT 1"; $ans = $db->query($sql); if($db->numRows($ans) == 0) { header("Locatio: index.php?mod=galleru"); die(); } $arr = $db->fetchAssoc($ans); echo "

Administrer kategori: {$arr['category']}

"; echo "

Tilbake

"; ?>