Location: PHPKode > scripts > PHPhotoalbum > phphotoalbum/delete_album.php
<?php
/*************************************************
 * PHPhotoalbum v0.5
 * by: Henning Støverud
 * e-mail: hide@address.com
 * URL: http://www.stoverud.com/PHPhotoalbum/
 *************************************************/

session_start(); 

include("config.inc.php");
include("functions.php");



// Accesscheck
if(!$_SESSION['logged_in'])
{
 echo "You are not logged in..";
 exit;
}

?>

<b>Deleting album <?=$_GET['id'];?></b>
<table border="1">

<?php

$connection = db_connect();
$query = "SELECT * FROM $config[TABLE_PICTURES] WHERE aid='$_GET[id]'";
$result = mysql_query($query);

$pidarray = array(); // Array to collect pids

// Delete all files
while($pic = mysql_fetch_array($result))
{
  $pidarray[] = $pic['pid'];

  $filename1 = $config['fullpath'].$pic['filepath'].$pic['filename'];
  $filename2 = $config['fullpath'].$pic['filepath']."thumb_".$pic['filename'];
  $filename3 = $config['fullpath'].$pic['filepath']."normal_".$pic['filename'];

  if(is_file($filename1)){
   if(unlink($filename1))
   	  echo "<tr><td>$filename1</td><td>Deleted</td></tr>\n";
  }
  if(is_file($filename2)){
   if(unlink($filename2))
 	  echo "<tr><td>$filename2</td><td>Deleted</td></tr>\n";
  }
  if(is_file($filename3)){
   if(unlink($filename3))
 	  echo "<tr><td>$filename3</td><td>Deleted</td></tr>\n";
  }
  flush();
}


// Delete all pictures
$query = "DELETE FROM $config[TABLE_PICTURES] WHERE aid='$_GET[id]'";
$result = mysql_query($query);
$affected = mysql_affected_rows();
if($affected > 0){
  echo "<tr><td>Database entries:</td><td> Deleted ($affected)</td></tr>\n";
  flush;
}

// Delete all comments
$count = 0;
for($i = 0; $i < count($pidarray); $i++)
{
  $query = "DELETE FROM $config[TABLE_COMMENTS] WHERE pid='$pidarray[$i]'";
  $result = mysql_query($query);
  $count += mysql_affected_rows();
}
echo "<tr><td>Comments:</td><td> Deleted ($count)</td></tr>\n";


// Delete album
$query = "DELETE from $config[TABLE_ALBUMS] WHERE aid='$_GET[id]'";
$result = mysql_query($query);
if(mysql_affected_rows() > 0)
  echo "<tr><td>Album $_GET[id]:</td><td> Deleted</td></tr>\n"
?>

</table>

<a href="index.php">Index</a><br>



Return current item: PHPhotoalbum