B
BlackLove2005
Datei galleries-admin.php
Datei images-admin.php
So nun hast du mal den ganzen Code. Ich werde heute Abend oder heute Nacht mal eine erklärung noch schreiben. Aber wie gessagt das kann sehr spät werden.
Gruß BlackLove2005
PHP:
<?php
$changesection="main";
$insert=$_POST["insert"];
$update=$_POST["update"];
$delete=$_GET["delete"];
$edit=$_GET["edit"];
if ($insert)
{
$galleryname=$_POST["galleryname"];
if ($galleryname)
{
$galleries=mysql_query("select * from galleries where gallery='$galleryname'",$db);
$gallery=mysql_fetch_assoc($galleries);
if (!$gallery)
{
mkdir("../../phptmp/thumbs/".$galleryname,0777);
mkdir("../../phptmp/images/".$galleryname,0777);
mysql_query("insert into galleries (gallery) values ('$galleryname')",$db);
$changes[$changesection].='Gallery <b>'.$galleryname.'</b> has been inserted into database<br>';
}
else
{
$changes[$changesection].='Gallery could not be inserted into database<br>';
$changes[$changesection].='Gallery <b>'.$galleryname.'</b> already exists<br>';
$changes[$changesection].='<hr>';
}
}
else
{
$changes[$changesection].='Gallery could not be inserted into database<br>';
$changes[$changesection].='Gallery missing<br>';
$changes[$changesection].='<hr>';
}
}
if ($update)
{
$galleryid=$_POST["galleryid"];
$galleryname=$_POST["galleryname"];
$galleries=mysql_query("select * from galleries where id='$galleryid'",$db);
$gallery=mysql_fetch_assoc($galleries);
if (($galleryname) && ($galleryname!=$gallery[gallery]))
{
$galleries=mysql_query("select * from galleries where gallery='$galleryname'",$db);
$gallery=mysql_fetch_assoc($galleries);
if (!$gallery)
{
$galleries=mysql_query("select * from galleries where id='$galleryid'",$db);
$gallery=mysql_fetch_assoc($galleries);
rename("../../phptmp/thumbs/".$gallery[gallery],"../../phptmp/thumbs/".$galleryname);
rename("../../phptmp/images/".$gallery[gallery],"../../phptmp/images/".$galleryname);
mysql_query("update galleries set gallery='$galleryname' where id='$galleryid'",$db);
$changes[$changesection].='Gallery has been changed to <b>'.$galleryname.'</b><br>';
}
else
{
$changes[$changesection].='Gallery could not be updated, gallery <b>'.$galleryname.'</b> already exists<br>';
}
}
}
if ($delete)
{
$galleries=mysql_query("select * from galleries where id='$delete'",$db);
$gallery=mysql_fetch_assoc($galleries);
$images=mysql_query("select * from images where gallery='$delete'",$db);
while ($image=mysql_fetch_assoc($images))
{
unlink("../../phptmp/thumbs/".$gallery[gallery]."/".$image[filename]);
unlink("../../phptmp/images/".$gallery[gallery]."/".$image[filename]);
}
rmdir("../../phptmp/thumbs/".$gallery[gallery]);
rmdir("../../phptmp/images/".$gallery[gallery]);
mysql_query("delete from images where gallery='$delete'",$db);
mysql_query("delete from galleries where id='$delete'",$db);
$changes[$changesection].='Gallery <b>'.$gallery[gallery].'</b> has been deleted from database<br>';
}
$changes[$changesection].='<form method="post" action="index.php?subsite=galleries-admin.php'.$sessionparm_link.'">';
$changes[$changesection].='<table class="vistable">';
if ($edit)
{
$galleries=mysql_query("select * from galleries where id='$edit'",$db);
$gallery=mysql_fetch_assoc($galleries);
$changes[$changesection].='<tr><td>Gallery:</td><td><input type="text" name="galleryname" value="'.$gallery[gallery].'"></td></tr>';
$changes[$changesection].='</table>';
$changes[$changesection].='<input type="hidden" name="galleryid" value="'.$gallery[id].'">';
$changes[$changesection].='<input type="submit" name="update" value="Update Gallery">';
$changes[$changesection].='<input type="submit" name="cancel" value="Cancel">';
}
else
{
$changes[$changesection].='<tr><td>Gallery:</td><td><input type="text" name="galleryname"></td></tr>';
$changes[$changesection].='</table>';
$changes[$changesection].='<input type="submit" name="insert" value="Add Gallery">';
$changes[$changesection].='</form>';
$changes[$changesection].='<table class="vistable" border="1">';
$changes[$changesection].='<tr><th>Gallery</th><th>Images</th><th colspan="3">Action</th></tr>';
$galleries=mysql_query("select * from galleries order by gallery",$db);
while ($gallery=mysql_fetch_assoc($galleries))
{
$images=mysql_query("select * from images where gallery='$gallery[id]'",$db);
$num_images=mysql_num_rows($images);
$changes[$changesection].='<tr><td>'.$gallery[gallery].'</td><td>'.$num_images.'</td>';
$changes[$changesection].='<td><a href="index.php?subsite=galleries-admin.php&edit='.$gallery[id].'">Edit</a></td>';
$changes[$changesection].='<td><a href="index.php?subsite=galleries-admin.php&delete='.$gallery[id].'">Delete</a></td>';
$changes[$changesection].='<td><a href="index.php?subsite=images-admin.php&gallery='.$gallery[id].'">Edit Images</a></td>';
$changes[$changesection].='</tr>';
}
$changes[$changesection].='</table>';
}
?>
Datei images-admin.php
PHP:
<?php
$changesection="main";
$galleryid=$_GET["gallery"];
if (!$galleryid)
{
header("Location:index.php?subsite=galleries-admin.php");
}
$changes[$changesection].='<a href="index.php?subsite=galleries-admin.php">Image Galleries Administration</a>';
$changes[$changesection].=' -> ';
$galleries=mysql_query("select * from galleries where id='$galleryid'",$db);
$gallery=mysql_fetch_assoc($galleries);
$changes[$changesection].='<b>'.$gallery[gallery].'</b><br><hr>';
$insert=$_POST["insert"];
$delete=$_GET["delete"];
if ($insert)
{
$tmpname=$_FILES["uploadfile"]["tmp_name"];
$filename=$_FILES["uploadfile"]["name"];
$filesize=$_FILES["uploadfile"]["size"];
$mimetype=$_FILES["uploadfile"]["type"];
if (($filesize>0) && ($mimetype=="image/jpeg") && (!file_exists("../../phptmp/images/".$gallery[gallery]."/".$filename)))
{
move_uploaded_file($tmpname,"../../phptmp/images/".$gallery[gallery]."/".$filename);
list($width,$height)=getimagesize("../../phptmp/images/".$gallery[gallery]."/".$filename);
$sourceimage=imagecreatefromjpeg("../../phptmp/images/".$gallery[gallery]."/".$filename);
$thumbwidth=90;
$thumbheight=round($thumbwidth*($height/$width));
$thumbimage=imagecreatetruecolor($thumbwidth,$thumbheight);
imagecopyresampled($thumbimage,$sourceimage,0,0,0,0,$thumbwidth,$thumbheight,$width,$height);
imagejpeg($thumbimage,"../../phptmp/thumbs/".$gallery[gallery]."/".$filename);
mysql_query("insert into images (filename,gallery) values ('$filename','$galleryid')",$db);
$changes[$changesection].='Image <b>'.$filename.'</b> has been uploaded<br>';
}
else
{
$changes[$changesection].='Image could not be uploaded<br>';
if ($mimetype!="image/jpeg")
{
$changes[$changesection].='File <b>'.$filename.'</b> is not a JPEG image<br>';
}
if (file_exists("../../phptmp/images/".$gallery[gallery]."/".$filename))
{
$changes[$changesection].='Image <b>'.$filename.'</b> already exists<br>';
}
$changes[$changesection].='<hr>';
}
}
if ($delete)
{
$images=mysql_query("select * from images where id='$delete'",$db);
$image=mysql_fetch_assoc($images);
mysql_query("delete from images where id='$delete'",$db);
unlink("../../phptmp/thumbs/".$gallery[gallery]."/".$image[filename]);
unlink("../../phptmp/images/".$gallery[gallery]."/".$image[filename]);
$changes[$changesection].='Image <b>'.$image[filename].'</b> has been deleted<br>';
}
$changes[$changesection].='<form method="post" action="index.php?subsite=images-admin.php&gallery='.$galleryid.$sessionparm_link.'" enctype="multipart/form-data">';
$changes[$changesection].='<input type="file" name="uploadfile">';
$changes[$changesection].='<input type="submit" name="insert" value="Upload Image">';
$changes[$changesection].='</form>';
$changes[$changesection].='<table class="vistable" border="1">';
$changes[$changesection].='<tr><th>Filename</th><th>Action</th></tr>';
$images=mysql_query("select * from images where gallery='$galleryid' order by filename",$db);
while ($image=mysql_fetch_assoc($images))
{
$changes[$changesection].='<tr><td>'.$image[filename].'</td>';
$changes[$changesection].='<td><a href="index.php?subsite=images-admin.php&gallery='.$galleryid.'&delete='.$image[id].$sessionparm_link.'">Delete</a></td>';
$changes[$changesection].='</tr>';
}
$changes[$changesection].='</table>';
?>
So nun hast du mal den ganzen Code. Ich werde heute Abend oder heute Nacht mal eine erklärung noch schreiben. Aber wie gessagt das kann sehr spät werden.
Gruß BlackLove2005