I'm using the following code to display images. what I would like to do is have a delete button under each image to delete that image if possible. The images are stored in a folder called photos.

Any help would be appreciated.

thanks.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Auto Generating Photo Gallery</title>

<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="resources/fancy.css" />

<script type="text/javascript" src="js/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="js/jquery.fancybox-1.0.0.js"></script>

</head>

<body>

<div id="page-wrap">



<?php

	/* settings */
	$image_dir = 'photos/';
	$per_column = 6;


	/* step one:  read directory, make array of files */
	if ($handle = opendir($image_dir)) {
		while (false !== ($file = readdir($handle))) 
		{
			if ($file != '.' && $file != '..') 
			{
				if(strstr($file,'thumb-'))
				{
					$files[] = $file;
				}
			}
		}
		closedir($handle);
	}



	/* step two: loop through, format gallery */
	if(count($files))
	{
		foreach($files as $file)
		{
			$count++;
			echo '<a class="photo-link" rel="one-big-group" href="',$image_dir,str_replace('thumb-','',$file),'"><img src="',$image_dir,$file,'" width="150"  />';
			echo str_replace('thumb-','',$file);
			echo '</a>';




			if($count % $per_column == 0) { echo '<div class="clear"></div>'; }
		}
	}
	else
	{
		echo '<p>There are no images in this gallery.</p>';
	}

?>

</div>

</body>

</html>

    do you really want random visitors to delete your images?

      dagon - how does that help?
      that comment would only be useful if added after something pertinent to the query

      Opie: you can add a link similar to :

      echo '<a href="thispage.php?del='.$filename.'"><img src="delbutton.gif"></a>';

      and at top of the script you do
      $filetodelete= $_GET['del'];

      then you add a delete function to remove the file

      of course you also need to ensure you check for sql injection, unregistered users deleting everything and handling errors from unexpected input

        cretaceous;10989501 wrote:

        dagon - how does that help?
        that comment would only be useful if added after something pertinent to the query

        I was checking the op understood the implications of what he was asking.:p

          Write a Reply...