rendered paste body<?php if(!isset($_SESSION['omg_admin'])) { header("Location: index.php?mod=admin"); die(); } if(!isset($_GET['gallery'])) { header("Location: index.php?mod=galleryAdmin"); die(); } set_time_limit(0); $gId = (int) $_GET['gallery']; if(isset($_GET['del'])) { $id = (int) $_GET['del']; $sql = "DELETE FROM omg_galleryImages WHERE id='$id' LIMIT 1"; $db->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 "<h1>Administrer kategori: {$arr['category']}</h1>"; echo "<p><a href='index.php?mod=galleryAdmin'>Tilbake</a></p>";?><script type="text/javascript" language="javascript"> var files=1; function addFile() { files ++; var tbl = document.getElementById('files'); var lastRow = tbl.rows.length; var row = tbl.insertRow(lastRow); // left cell var cellLeft = row.insertCell(0); var textNode = document.createTextNode("Tittel #"+files); cellLeft.appendChild(textNode); //right cell var cellRight = row.insertCell(1); var el = document.createElement('input'); el.type = 'text'; el.name = 'img_title'+files; cellRight.appendChild(el); var row = tbl.insertRow(lastRow+1); // left cell var cellLeft = row.insertCell(0); var textNode = document.createTextNode("Fil #"+files); cellLeft.appendChild(textNode); //right cell var cellRight = row.insertCell(1); var el = document.createElement('input'); el.type = 'file'; el.name = 'img_file'+files; cellRight.appendChild(el); }</script><div id="gallery"> <?php if(isset($error)) { echo "<p style='color:#f55'>$error</p>"; } ?> <p>Last opp bilde</p> <form method="post" action="" enctype="multipart/form-data"> <table width="100%" id="files"> <tr> <td>Titte #l:</td> <td><input type="text" name="img_title1" /></td> </tr> <tr> <td>Fil #1:</td> <td><input type="file" name="img_file1" /></td> </tr> </table> <br /> <bR /> <p><a href="#" onclick="addFile()">Flere fil felt</a></p> <p><input type="submit" name="img_do" value="Last opp" /></p> </form></div><br /><div id="gallery" class="images"> <table width="100%" cellspacing="5" cellpadding="5"> <?php $sql = "SELECT id, image, thumb, title, DATE_FORMAT(date,'%d.%m.%Y') AS t FROM omg_galleryImages WHERE category_id='$gId'"; $ans = $db->query($sql); if($db->numRows($ans) == 0) { echo "<tr><td align='center'>Det er ingen bilder i dette galleriet.</td></tr>"; } else { $i = 0; echo "<tr>"; while($arr = $db->fetchAssoc($ans)) { $id = $arr['id']; $thumb = $arr['thumb']; $date = $arr['t']; $num = 1; $sql2 = "SELECT id FROM omg_galleryComments WHERE image='$id'"; $ans2 = $db->query($sql2); $numComments = $db->numRows($ans2); echo "<td align='center'><a><img src='gfx/gallery/$thumb' alt='»' /><br />$date<br /></a><a href='index.php?mod=galleryAdminCategory&gallery=$gId&del=$id' onclick='return confirm(\"Sikker på at du vil slette dette bilde? Alle kommentarene forsvinner også.\")'>Slett bilde</a></td>"; $i++; if($i == 5) { $i = 0; echo "</tr><tr>"; } } if($i < 5) { echo "<td colspan='".(5-$i)."'> </td>"; } echo "</tr>"; } ?> </table></div>