写真を表示してカテゴリを作成するためのスクリプトを見つけましたが、編集した後でも、やりたいことがすべて実行できません。最大の問題は、JPEGファイルしか表示されないことですが、PNGとGIFも表示するにはどうすればよいですか?また、ディレクトリ内のフォルダを使用してカテゴリを作成しますが、ユーザーがどのカテゴリに分類されるかを選択できるようにする方法がわかりません。どうすればよいですか?
<body link="#622d15"><form name="newad" method="post" enctype="multipart/form-data"
action="">
<?php
$title="HBCC Photo";
// Logo for the site. Use HTML it can be a graphic.
$logo='';
//Thumbnail maker. Some servers don't like this. Defualt is to leave it on. If you have trouble turn it off.
//0=off 1=on
$makethumbs=1;
//Thumbnail extension. You can change the thumbnail filename extesntion that is added onto the end of the original filename.
//Thumbnail file name will be "OriginalFilename.jpg_thmb.jpg" Warning if you leave this blank you will overwrite your original files!
//If you change the extension it will create new thumbnail files, but not delete the old ones.
// default=_thmb.jpg
$thumbext='_thmb.jpg';
//Thumbnail size. The minimum width and height in pixels, that you would like the thumbnails to be. Photos are scaled.
$twidth=150;
$theight=150;
//Photo size. The minimum width and height in pixels, that you would like you photos scaled to when displayed.
$pwidth = 540;
$pheight = 540;
//The thumbnail gallery is displayed in a table. Please choose the number of rows and columns you would like.
$rows=3;
$cols=3;
//If you would like the filename of the photo to be displayed under the thumbnail change this setting.
//0=off 1=on
$showfilename=1;
$showpathname=0;
//If you want the EXIF Comment information shown
//0=off 1=on
$showexifcomment=1;
//If you would like photo to up a new window when clicked change this setting.
//The defualt is to open the image up in the same browser window.
//0=off 1=on
$window=0;
//Use Javascript for new window
//0=off 1=on
$javascript=0;
//If you would like the thumb to link directly to the photo and not the script set this.
//This works best if you use the Javascript window. It pops open in a nice size.
//Default is to the script.
//0=off 1=on
$linktophoto=0;
//If you would like to use a custom header or footer please add the file names here and they will be included in the script.
//Otherwise the plain jane default will be used. The files should be in the same folder as the script, but if you provide an
//alternate path it will work as well. Example: header.html, header.php.
$header="NULL";
$footer="NULL";
$divider=" | "; //divider between album names
$pagedivider=" | "; //divider between page numbers in thumbnail view
//No need to mess with anything below here.
error_reporting(E_ALL & ~E_NOTICE);
//Part of this function comes from http://www.php.net/manual/en/function.getimagesize.php
function thumb_maker($filename, $minwidth, $minheight) {
global $thumbext,$makethumbs;
if ($makethumbs==1) {
if (file_exists($filename.$thumbext)) {
$photosize = getimagesize($filename.$thumbext);
if (max($minwidth,$minheight)!=max($photosize[0],$photosize[1])) {
unlink($filename.$thumbext);
}
}
if (!file_exists($filename.$thumbext) && file_exists($filename)) {
echo "<br/>One moment please....creating a thumbnail. Refresh the page in a moment.";
set_time_limit(60);
$photosize = getimagesize($filename);
// Get image size and scale ratio
$scale = min($minwidth/$photosize[0], $minheight/$photosize[1]);
if ($scale < 1) {
$width = floor($scale*$photosize[0]);
$height = floor($scale*$photosize[1]);
}
else {
$width = $minwidth;
$height = $minheight;
}
if ($photosize['mime']=="image/jpeg") {
$resizedimage = imagecreatetruecolor($width, $height);
$thumbimage = imagecreatefromjpeg($filename);
imagecopyresampled($resizedimage, $thumbimage, 0, 0, 0, 0, $width, $height, $photosize[0], $photosize[1]);
imagejpeg($resizedimage,$filename.$thumbext,50);
imageDestroy($resizedimage);
imageDestroy($thumbimage);
}
}
}
}
//Part of this function comes from http://www.php.net/manual/en/function.getimagesize.php
function gallery_sizer($photo,$minwidth,$minheight) {
if (file_exists($photo)) {
$photosize = getimagesize("$photo");
# Get image size and scale ratio
$scale = min($minwidth/$photosize[0], $minheight/$photosize[1]);
if ($scale <= 1) {
$width = floor($scale*$photosize[0]);
$height = floor($scale*$photosize[1]);
}
else {
$width = floor($photosize[0]);
$height = floor($photosize[1]);
}
return array($width,$height,$photosize[0],$photosize[1]);
}
}
function exif_comment($photo) {
$comment=NULL;
if (file_exists($photo) && function_exists('exif_read_data')) {
$exif = exif_read_data($photo, 0, true);
if (array_key_exists('COMMENT', $exif)) {
$comment=str_replace("\n", "<br />", strip_tags($exif['COMMENT'] [0]));
}
}
return $comment;
}
function getdirs($dir) {
$dirs=array();
chdir($dir);
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".."){
if (is_dir($file)) {
$dirs[] = $file;
}
}
}
closedir($handle);
}
sort($dirs);
return $dirs;
}
function getphotos($photodir) {
global $thumbext;
$photos=array();
if ($handle = opendir($photodir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && !eregi(".jpg".$thumbext."$",$file) && eregi(".jpg$",$file)){
$photos[] = $file;
}
}
closedir($handle);
}
sort($photos);
return $photos;
}
function thumb_gallery($photonum) {
global $photos, $photourl, $photodir, $twidth, $theight, $rows, $cols, $showfilename,$showpathname,$showexifcomment,$linktophoto,$thumbext, $album, $window, $javascript, $query, $pagedivider;
if ($photonum>count($photos)-1) {
$photonum=count($photos)-1;
}
if (($photonum)<=0) {
$photonum=0;
}
if(isset($album)) { $query="&album=".urlencode($album); }
for ($tr = 1; $tr <= $rows; $tr++) {
$photobody[]="<tr>";
for ($td = 1; $td <= $cols; $td++) {
$photobody[]="<td align=\"center\" valign=\"top\">";
if (array_key_exists($photonum, $photos)) {
if (file_exists($photodir."/".$photos[$photonum].$thumbext)) {
$size=gallery_sizer($photodir."/".$photos[$photonum].$thumbext,$twidth,$theight);
$comment=exif_comment($photodir."/".$photos[$photonum]);
$jswindowsize=gallery_sizer($photodir."/".$photos[$photonum],1,1);
$link = $photourl."/".$photos[$photonum].$thumbext;
if ($linktophoto==1) { $linktarget="http://".$_SERVER['HTTP_HOST'].$photourl."/".$photos[$photonum]; } else { $linktarget="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."? p=".urlencode($photos[$photonum]).$query; }
if ($window==1) { if ($javascript==1) { $linktarget='javascript:Popup(\''.$linktarget.'\',\''.($jswindowsize[2]+15).'\',\''. ($jswindowsize[3]+15).'\')'; } else { $target="_blank"; } } else { $target="_self"; }
if ($photonum<=count($photos)-1) {
if ($javascript==0) {
$photobody[]="<a href=\"$linktarget\" target=\"$target\">";
}
else { $photobody[]="<a href=\"$linktarget\">"; }
}
$photobody[]="<img src=\"$link\" width=\"$size[2]\" height=\"$size[3]\" alt=\"$photos[$photonum]\" border=\"1\" /></a><br />";
}
if ($photos[$photonum]) {
if ($showexifcomment==1 && !is_null($comment)) { $photobody[]='<p class="thmbcaption">'.$comment.'</p>'; }
if ($showfilename==1) { $photobody[]='<p class="thmbcaption">'.$photos[$photonum].'</p>'; }
if ($showpathname==1) { $photobody[]='<p class="thmbcaption">http://'.$_SERVER['HTTP_HOST'].$photourl.'/'.$photos[$photonum].'</p>'; }
}
}
$photobody[]="</td>";
$photonum++;
}
$photobody[]="</tr>";
}
unset($tr, $td);
#this is down here for a reason don't move it and use array_unshift instead. Trust me.
if (($photonum-($rows*$cols))>0) { $prev="<a href=\"".$_SERVER['PHP_SELF']."?pn=".($photonum-(($rows*$cols)*2)).$query."\"><< Previous</a>"; } else { $prev=""; }
if (($photonum)<(count($photos))) { $next="<a href=\"".$_SERVER['PHP_SELF']."?pn=".$photonum.$query."\">Next>></a>"; } else { $next=""; }
$photopage=array();
$photopage[]="Pages: ";
for ($pagelink=0, $pagenum=1; $pagelink<=count($photos); $pagelink+= ($rows*$cols), $pagenum++) {
//thanks to DC for this addition.
if ($pagenum > 1){
$photopage[]=$pagedivider."<a href=\"$_SERVER[PHP_SELF]?pn=". ($pagelink).$query."\">$pagenum</a> ";
}
else {
$photopage[]=" <a href=\"$_SERVER[PHP_SELF]?pn=". ($pagelink).$query."\">$pagenum</a> ";
}
}
unset($pagelink, $pagenum);
$photopage=implode("", $photopage);
if ($photonum >= count($photos)) { $endnum=count($photos); } else { $endnum=$photonum; }
$photobody[]="<tr><td colspan=\"".$cols."\"><table width=\"100%\" border=\"0\"><tr><td width=\"33%\"><div align=\"left\" class=\"caption\">".$prev."</div> </td><td width=\"33%\"><div align=\"center\" class=\"caption\">Photos <strong>".($photonum- (($rows*$cols)-1))."</strong> to <strong>".$endnum."</strong> of <strong>".count($photos)." </strong><br />".$photopage."</div></td><td width=\"33%\"><div align=\"right\" class=\"caption\">".$next."</div></td></tr></table></td></tr>";
array_unshift($photobody, "<tr><td colspan=\"".$cols."\"><table width=\"100%\" border=\"0\"><tr><td width=\"33%\"><div align=\"left\" class=\"caption\">".$prev."</div></td><td width=\"33%\"><div align=\"center\" class=\"caption\">Photos <strong>".($photonum-(($rows*$cols)-1))."</strong> to <strong>".$endnum."</strong> of <strong>".count($photos)."</strong><br />".$photopage." </div></td><td width=\"33%\"><div align=\"right\" class=\"caption\">".$next."</div></td> </tr></table></td></tr>");
#put the table tag at the top of the array.
array_unshift($photobody, '<table width="100%" border="0" cellspacing="0" cellpadding="3">');
$photobody[]='</table>';
if ($window==1 && $javascript==1) {
array_unshift($photobody, '<SCRIPT language="JavaScript">function Popup(url,width,height) { PopupWindow = window.open (\'\', \'PopupWindow\',\'scrollbars=0,resizable=1,height=\'+height+\',width=\'+width+\',left=100,t op=20\'); PopupWindow.focus(); PopupWindow.location.href = url; }</SCRIPT>');
}
return $photobody;
}
function photo_gallery($photo) {
global $photodir, $photourl, $pwidth, $pheight, $thumbsurl, $window, $photos, $album, $thumbext, $header,$showfilename,$showpathname,$showexifcomment;
$photobody=array();
if (isset($photo)) {
if(isset($album)) { $query="&album=".urlencode($album); }
foreach ($photos as $key => $value) {
if($photo==$value) {
if (array_key_exists($key+1, $photos)) {
if($photos[$key+1]) {
$nextphoto="<br /><a href=\"".$_SERVER['PHP_SELF']."? p=".$photos[$key+1].$query."\">Next Photo ></a>";
$nextphotothumb="<a href=\"".$_SERVER['PHP_SELF']."? p=".$photos[$key+1].$query."\"><img alt=\"\" src=\"".$photourl."/".$photos[$key+1].$thumbext."\" height=\"50\" border=\"1\" /></a>";
}
}
else {
$nextphoto=NULL;
$nextphotothumb=NULL;
}
if (array_key_exists($key-1, $photos)) {
if($photos[$key-1]) {
$prevphoto="<br /><a href=\"".$_SERVER['PHP_SELF']."?p=".$photos[$key- 1].$query."\">< Previous Photo</a>";
$prevphotothumb="<a href=\"".$_SERVER['PHP_SELF']."?p=".$photos[$key- 1].$query."\"><img alt=\"\" src=\"".$photourl."/".$photos[$key-1].$thumbext."\" height=\"50\" border=\"1\" /></a>";
}
}
else {
$prevphoto=NULL;
$prevphotothumb=NULL;
}
}
}
$size=gallery_sizer($photodir.'/'.$photo,$pwidth,$pheight);
$comment=exif_comment($photodir.'/'.$photo);
//close window or prev next menu section
$photobody[]='<table width="100%" border="0" cellspacing="0" cellpadding="3">';
$photobody[]="<tr class=\"imageborder\"><td width=\"33%\"></td><td align=\"center\" width=\"33%\"><div align=\"center\" class=\"caption\"></div></td><td align=\"right\" width=\"33%\"></td></tr>";
if ($window==1) {
$photobody[]="<tr class=\"imageborder\"><td width=\"33%\"><a href=\"javascript:window.close()\">Close Window</a></td><td align=\"center\" width=\"33%\"> <div align=\"center\" class=\"caption\">";
$photobody[]="</div></td><td align=\"right\" width=\"33%\"></td></tr>";
}
else {
$photobody[]="<tr class=\"imageborder\"><td width=\"33%\"><div align=\"left\" class=\"caption\">".$prevphotothumb.$prevphoto."</div></td><td align=\"center\" width=\"33%\"><div align=\"center\" class=\"caption\">";
if ($header=="NULL") {
if (isset($album)) { $photobody[]="<a href=\"".$_SERVER['PHP_SELF']."?album=".urlencode($album)."&p=".$photo."&slide=1\">Start Slideshow</a>\n"; }
else { $photobody[]="<a href=\"".$_SERVER['PHP_SELF']."? p=".$photo."&slide=1\">Start Slideshow</a>\n"; }
}
$photobody[]="</div></td><td align=\"right\" width=\"33%\"><div align=\"right\" class=\"caption\">".$nextphotothumb.$nextphoto."</div></td></tr>";
}
$photobody[]='<tr><td colspan="3" align="center">';
$photobody[]='<img src="'.$photourl.'/'.$photo.'" width="'.$size[0].'" height="'.$size[1].'" border="0" alt="" class="imageborder" />';
if ($photo) {
if ($showexifcomment==1) { $photobody[]='<p class="photocaption">'.$comment.'</p>'; }
if ($showfilename==1) { $photobody[]='<p class="photocaption">'.$photo.'</p>'; }
if ($showpathname==1) { $photobody[]='<p class="photocaption">http://'.$_SERVER['HTTP_HOST'].$photourl.'/'.$photo.'</p>'; }
}
$photobody[]='</td></tr>';
$photobody[]='</table>';
}
return $photobody;
}
function photo_slides($photo) {
global $photodir, $photourl, $pwidth, $pheight, $thumbsurl, $window, $photos, $album, $thumbext, $header,$showfilename,$showpathname,$showexifcomment;
$photobody=array();
if (isset($photo)) {
if(isset($album)) { $query="&album=".urlencode($album); }
foreach ($photos as $key => $value) {
if($photo==$value) {
if (array_key_exists($key+1, $photos)) {
if($photos[$key+1]) {
$nextphoto="<br /><a href=\"".$_SERVER['PHP_SELF']."? p=".$photos[$key+1].$query."\">Next Photo ></a>";
$nextphotothumb="<a href=\"".$_SERVER['PHP_SELF']."? p=".$photos[$key+1].$query."\"><img alt=\"\" src=\"".$photourl."/".$photos[$key+1].$thumbext."\" height=\"50\" border=\"1\" /></a>";
}
}
else {
$nextphoto=NULL;
$nextphotothumb=NULL;
}
if (array_key_exists($key-1, $photos)) {
if($photos[$key-1]) {
$prevphoto="<br /><a href=\"".$_SERVER['PHP_SELF']."?p=".$photos[$key- 1].$query."\">< Previous Photo</a>";
$prevphotothumb="<a href=\"".$_SERVER['PHP_SELF']."?p=".$photos[$key- 1].$query."\"><img alt=\"\" src=\"".$photourl."/".$photos[$key-1].$thumbext."\" height=\"50\" border=\"1\" /></a>";
}
}
else {
$prevphoto=NULL;
$prevphotothumb=NULL;
}
}
}
$size=gallery_sizer($photodir.'/'.$photo,$pwidth,$pheight);
$comment=exif_comment($photodir.'/'.$photo);
$photobody[]='<table width="100%" border="0" cellspacing="0" cellpadding="3">';
$photobody[]="<tr class=\"imageborder\"><td width=\"33%\"><div align=\"left\" class=\"caption\">".$prevphotothumb.$prevphoto."</div></td><td align=\"center\" width=\"33%\"><div align=\"center\" class=\"caption\">";
if ($header=="NULL") {
if (isset($album)) { $photobody[]="<a href=\"".$_SERVER['PHP_SELF']."? album=".urlencode($album)."&p=".$photo."\">Stop Slideshow</a>\n"; }
else { $photobody[]="<a href=\"".$_SERVER['PHP_SELF']."?p=".$photo."\">Stop Slideshow</a>\n"; }
}
$photobody[]="</div></td><td align=\"right\" width=\"33%\"><div align=\"right\" class=\"caption\">".$nextphotothumb.$nextphoto."</div></td></tr>";
//if ($window==1) { $target="<a href=\"javascript:window.close()\">Close Window</a>"; } else { $target="<a href=\"".$_SERVER['HTTP_REFERER']."\">Back</a>"; }
$photobody[]='<tr><td colspan="3" align="center">';
$photobody[]='<img src="'.$photourl.'/'.$photo.'" width="'.$size[0].'" height="'.$size[1].'" border="0" alt="" class="imageborder" />';
if ($photo) {
if ($showexifcomment==1) { $photobody[]='<p class="photocaption">'.$comment.'</p>'; }
if ($showfilename==1) { $photobody[]='<p class="photocaption">'.$photo.'</p>'; }
if ($showpathname==1) { $photobody[]='<p class="photocaption">http://'.$_SERVER['HTTP_HOST'].$photourl.'/'.$photo.'</p>'; }
}
$photobody[]='</td></tr>';
$photobody[]='</table>';
}
return $photobody;
}
function display($photobody) {
global $photodir;
getheader();
echo "<!--Created by LGR Computer Enterprises. www.lgr.ca-->\n";
albums(dirname($_SERVER['SCRIPT_FILENAME']));
echo "<div class=\"photobody\">";
foreach ($photobody as $value) {
echo $value."\n";
}
echo "</div>";
getfooter();
exit;
}
function albums($dir) {
//for now only one level of albums works.
global $album, $title, $photos, $divider, $logo, $photo;
$dirs=getdirs($dir);
if (isset($logo)) { echo $logo; }
if (isset($album)) { echo "<h1>".$album."</h1>"; } else { echo "<h1>".$title."</h1> <p>Albums Available</p>"; }
echo "<div class=\"album\"><p>";
if (isset($album) || isset($photo)) { echo "<a href=\"".$_SERVER['PHP_SELF']."\">$title Home</a>$divider\n"; }
else { }
if (count($dirs)>0) {
foreach ($dirs as $value) {
echo "<a href=\"".$_SERVER['PHP_SELF']."? album=".urlencode($value)."\">".$value."</a>$divider\n";
}
}
echo "</p></div>";
}
//returns the header for the page. Checks for a user defined header.
function getheader() {
global $header, $title, $slide, $photodir, $photourl, $pwidth, $pheight, $thumbsurl, $window,$photo, $photos, $album, $stylesheet;
if(isset($album)) { $query="&album=".urlencode($album); }
if ($slide==1) { $query=$query."&slide=1"; }
foreach ($photos as $key => $value) {
if($photo==$value) {
if (array_key_exists($key+1, $photos)) {
if($photos[$key+1]) {
$nextslide=$_SERVER['PHP_SELF']."?p=".$photos[$key+1].$query;
}
}
else {
$slide=0;
}
}
}
if (isset($header) && $header!="NULL" && is_file ($header)) {
require("$header");
}
else {
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"';
echo "\n";
echo '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
echo "\n";
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >';
echo "\n";
echo '<head>';
echo '<meta http-equiv="content-type" content="text/html; charset=iso-8859- 1" />';
echo "\n";
echo "<title>$title</title>\n";
echo '<meta name="author" content="Lee Robertson"/>';
if ($slide==1 && $header=="NULL") { echo "<META HTTP-EQUIV=refresh CONTENT=\"4; URL=".$nextslide." \">"; }
echo '<style type="text/css" media="all">@import "'.$stylesheet.'"; </style>';
echo "\n";
echo '</head>';
echo "\n";
echo '<body>';
echo "\n";
}
}
//returns the footer for the page. Checks for a user defined footer.
function getfooter() {
global $footer;
if (isset($footer) && $footer!="NULL" && is_file ($footer)) {
require("$footer");
}
else {
echo '<div class="lgrfooter"><p>Powered by: <a href="http://www.photogallery.lgr.ca">LGR Photo</a></p><p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid- xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p></div>';
echo '</body></html>';
}
}
$photodir=dirname($_SERVER['SCRIPT_FILENAME']);
$photourl=dirname($_SERVER['PHP_SELF']);
$thumbsurl=dirname($_SERVER['PHP_SELF']);
$photobody=array();
if (isset($_GET['album'])) {
if (in_array($_GET['album'],getdirs(dirname($_SERVER['SCRIPT_FILENAME'])))==FALSE) {
$album = NULL;
}
else {
$album = urldecode($_GET['album']);
}
$photodir=dirname(realpath($_SERVER['SCRIPT_FILENAME']))."/".$album;
$photourl=dirname($_SERVER['PHP_SELF'])."/".$album;
$thumbsurl=dirname($_SERVER['PHP_SELF'])."/".$album;
}
//To make sure this works both on Linux and Win
$photodir = str_replace("\\", "/", $photodir);
//Get the jpegs from the folder.
$photos=getphotos($photodir);
//check to see if thumbnails are made if not it will make. Adds time to the processing of the script.
for ($i=0; $i<=count($photos)-1; $i++) {
thumb_maker($photodir."/".$photos[$i], $twidth, $theight);
}
if (count($photos)<=0) {
$photobody[]="";
display($photobody);
exit;
}
if (isset($_GET['pn'])) {
$photonum = htmlentities(strip_tags($_GET['pn']));
$photobody=thumb_gallery($photonum);
}
elseif (isset($_GET['slide'])) {
$slide=$_GET['slide'];
$photo=htmlentities(strip_tags(urldecode($_GET['p'])));
if (file_exists($photodir.'/'.$photo)) {
$photobody=photo_slides($photo,$pwidth,$pheight);
}
else {
$photobody=thumb_gallery(0);
}
}
elseif (isset($_GET['p'])) {
$photo=htmlentities(strip_tags(urldecode($_GET['p'])));
if (file_exists($photodir.'/'.$photo)) {
$photobody=photo_gallery($photo,$pwidth,$pheight);
}
else {
$photobody=thumb_gallery(0);
}
}
else {
$photobody=thumb_gallery(0);
}
//output it all to the browser.
display($photobody);
exit;
?>