diff pics/common.php @ 0:561c0b0f3234

initial add
author paulo@twcdns.fastsearch.net
date Wed, 21 Jul 2010 00:11:54 -0700
parents
children 2ede1c948f35
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/pics/common.php	Wed Jul 21 00:11:54 2010 -0700
     1.3 @@ -0,0 +1,80 @@
     1.4 +<?php
     1.5 +	$thumbs_dir = "thumbs/";
     1.6 +	$browse_dir = "browse/";
     1.7 +
     1.8 +	function listThumbs($thumbs_dir) {
     1.9 +		$dh = opendir($thumbs_dir);
    1.10 +		if ($dh) {
    1.11 +			while (($file = readdir($dh)) !== false) {
    1.12 +			   if (strncmp($file, ".", 1) != 0)
    1.13 +			      $files[] = $file;
    1.14 +			}
    1.15 +			
    1.16 +			sort($files, SORT_NUMERIC);
    1.17 +			foreach ($files as $file)
    1.18 +			   echo '<A HREF="browse.php?id=' . $file . '"><IMG SRC="' . $thumbs_dir . $file . '"></A> ' . "\n";
    1.19 +			
    1.20 +			closedir($dh);
    1.21 +		}
    1.22 +	}
    1.23 +
    1.24 +	function browse($browse_dir, $thumbs_dir) {
    1.25 +		include('../../../login.php');
    1.26 +
    1.27 +		$database = 'pauloang_pics';
    1.28 +
    1.29 +		$link = mysql_connect('localhost', $username, $password);
    1.30 +		if (!$link)
    1.31 +			die('Could not connect to MySQL server: ' . mysql_error());
    1.32 +	
    1.33 +		$db_selected = mysql_select_db($database, $link);
    1.34 +		if (!$db_selected)
    1.35 +			die('Could not select database: ' . mysql_error());
    1.36 +	
    1.37 +
    1.38 +		foreach ($_GET as $getKey => $getValue) {
    1.39 +			if ($getKey == "id" && !empty($_GET[$getKey])) {
    1.40 +				$dh = opendir($browse_dir);
    1.41 +				if ($dh) {
    1.42 +					while (($file = readdir($dh)) !== false) {
    1.43 +						if (strncmp($file, ".", 1) != 0)
    1.44 +							$files[] = $file;
    1.45 +					}
    1.46 +				}
    1.47 +				closedir($dh);
    1.48 +
    1.49 +				sort($files, SORT_NUMERIC);
    1.50 +				for ($i = 0, $size = sizeof($files); $i < $size; $i++) {
    1.51 +					if ($files[$i] == $getValue) {
    1.52 +						if ($i > 0) {
    1.53 +							echo '<A HREF=browse.php?id=' . $files[$i - 1] . '>';
    1.54 +							echo '<IMG SRC="' . $thumbs_dir . $files[$i - 1]. '">';
    1.55 +							echo '</A>' . "\n";
    1.56 +						}
    1.57 +						if ($i < $size - 1) {
    1.58 +							echo '<A HREF=browse.php?id=' . $files[$i + 1] . '>';
    1.59 +							echo '<IMG SRC="' . $thumbs_dir . $files[$i + 1]. '">';
    1.60 +							echo '</A>' . "\n";
    1.61 +						}
    1.62 +						echo '<br>' . "\n";
    1.63 +						echo '<A HREF="./">';
    1.64 +						echo '<IMG SRC="' . $browse_dir . $files[$i] . '"> ';
    1.65 +						echo '</A>' . "\n";
    1.66 +
    1.67 +						$query = 'SELECT * FROM '. basename(getcwd()) . ' WHERE id = "' . $getValue . '"';
    1.68 +						$results = mysql_query($query);
    1.69 +
    1.70 +						if ($results) {
    1.71 +							$row = mysql_fetch_assoc($results);
    1.72 +							$caption = $row['caption'];
    1.73 +							echo '<P>' . $caption . '</P>' . "\n";
    1.74 +						}
    1.75 +
    1.76 +						break;
    1.77 +					}
    1.78 +				}
    1.79 +				break;
    1.80 +			}
    1.81 +		}
    1.82 +	}
    1.83 +?>