Jump to content

Need help adding delete checkboxes to this gallery script.


Scuba_Steve

Recommended Posts

Hey everyone. I need some help with adding check boxes to this gallery script i found with a delete button. I have made a gallery with exactly what im looking for but it looks terrible and would rather use this premade one but im having trouble adding everything. Any help would be greatly appreciated. Thanks.  :D

 

Script i want the check boxes and delete button added to.

 

<?php
/*************************************************
* Micro Photo Gallery
*
* Version: 1.0
* Date: 2007-04-05
*
* Usage:
* Just copy these files into your image folder
*
****************************************************/

$columns     = 5;
$thmb_width  = 120;
$thmb_height = 80;

function resizeImage($originalImage,$toWidth,$toHeight){
    
    // Get the original geometry and calculate scales
    list($width, $height) = getimagesize($originalImage);
    $xscale=$width/$toWidth;
    $yscale=$height/$toHeight;
    
    // Recalculate new size with default ratio
    if ($yscale>$xscale){
        $new_width = round($width * (1/$yscale));
        $new_height = round($height * (1/$yscale));
    }
    else {
        $new_width = round($width * (1/$xscale));
        $new_height = round($height * (1/$xscale));
    }
    // Resize the original image
    $imageResized = imagecreatetruecolor($new_width, $new_height);
    $imageTmp     = imagecreatefromjpeg ($originalImage);
    imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    return $imageResized;
} 

function generateThumbnails(){
global $thmb_width,$thmb_height;

// Open the actual directory
if ($handle = opendir(".")) {
	// Read all file from the actual directory
	while ($file = readdir($handle))  {
		// Check whether tha actual item is a valid file
		if (is_file($file)){
			// Check whether the actual image is a thumbnail
      		if (strpos($file,'_th.jpg')){
      			$isThumb = true;
      		} else {
	      		$isThumb = false;
	      	}
      	
      		if (!$isThumb) {
	      		// Process the file string
      			$dirName  = substr($file,0,strpos($file,basename($file)));
      			if (strlen($dirName) < 1) $dirName = '.';
      			$fileName = basename($file);
      			$fileMain = substr($fileName,0,strrpos($fileName,'.'));
      			$extName  = substr($fileName,strrpos($fileName,'.'),
      								strlen($fileName)-strrpos($fileName,'.'));
  					
      			// Check if the actual file is a jpeg image
      			if (($extName == '.jpg') || ($extName == '.jpeg')){
		    		$thmbFile = $dirName.'/'.$fileMain.'_th.jpg';
		    		// If a thumbnail dosn't exists tahn create a new one
		    		if (!file_exists($thmbFile)){
			    		imagejpeg(resizeImage($file,$thmb_width,$thmb_height),$thmbFile,80);
			    	}
				}
      		} 
   		}
   		}
}

}

function getNormalImage($file){
$base = substr($file,0,strrpos($file,'_th.jpg'));
if (file_exists($base.'.jpg')) return $base.'.jpg';
elseif (file_exists($base.'.jpeg')) return $base.'.jpeg';
else return "";
}

function displayPhotos(){
global $columns;

generateThumbnails();
$act = 0;
// Open the actual directory
if ($handle = opendir(".")) {
	// Read all file from the actual directory
	while ($file = readdir($handle))  {
		// Check whether tha actual item is a valid file
		if (is_file($file)){
			// Check whether the actual image is a thumbnail
      		if (strpos($file,'_th.jpg')){
				++$act;
				if ($act > $columns) {
					echo '</tr><tr><td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/></a></td>';	
					$act = 1;
				} else {
					echo '<td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/></a></td>';	
				}
      			
      		}
      	}
	}
}	
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Micro Photo Gallery</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <div id="main">
    <div class="caption">Micro Photo Gallery</div>
      <table align="center"><tr>     
    		<?php displayPhotos(); ?>
      </table>		
    		
<div id="source">Micro Photo Gallery 1.0</div>
  </div>
</body>   

 

Script i made so you can understand what i mean.

 

<?php
require_once('common.php');
checkUser();
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="shadowbox.css">
<script type="text/javascript" src="shadowbox.js"></script>
<script type="text/javascript">
Shadowbox.init();
</script>
</head>
<body>
<body background="bg.gif">
</body>
</html>
<?php
$path = "images";

if(isset($_POST['file']) && is_array($_POST['file']))
{
foreach($_POST['file'] as $file)
{	
	unlink($path . "/" . $file) or die("Failed to delete file");
}
}
?>
<form name="form1" method="post">
<?php
$path = "images";
$dir_handle = @opendir($path) or die("Unable to open folder");

while (false !== ($file = readdir($dir_handle))) {

if($file == "index.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;

echo "<input type='CHECKBOX' name='file[]' value='$file'>";
echo "<a href='$path/$file' alt='$file' rel=shadowbox><img width=200px height=200px src='$path/$file' alt='$file'></a>";

}
closedir($dir_handle);
?>
<iframe src="views.php" width="100%" height="200px"></iframe>
<center><br><br><input type="submit" name="Delete" value="Delete"><br><br>
</form>
<FORM METHOD="LINK" ACTION="logout.php">
<INPUT TYPE="submit" VALUE="LogOut"></center>
</FORM>

Link to comment
Share on other sites

  • 4 weeks later...

It might be that there are no replies for the purpose that it isn't any technical help with programming itself. It seems as though it's a request, in which case, you may need to hire a programmer.

 

If on the other hand, you have a SPECIFIC question and have tried programming it yourself, and need assistance in seeing what went wrong, then you can post that.

 

Not trying to be narcissistic or anything.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.