0

所以我抓住了 LGRphoto 不再支持的非常好的但有点旧的 PHP 脚本。发现 FUNCTION eregi() 已弃用,因此将其替换为 preg_match()。似乎使脚本工作正常,除了 2 个错误。认为这可能是一个正则表达式问题,但谷歌搜索暗示这可能是 PHP 中的本机错误。也许有真正编程经验的人可以弄清楚或告诉我这不是我需要担心的事情。谢谢。

这是堆栈跟踪:

( ! ) Warning: preg_match(): Unknown modifier 'j' in C:\....\.php on line 194
Call Stack
#   Time    Memory  Function    Location
1   0.0024  397784  {main}( )   ..\lgrphoto.php:0
2   0.0035  402768  getphotos( )    ..\lgrphoto.php:522
3   0.9499  404696  preg_match ( )  ..\lgrphoto.php:194

( ! ) Warning: preg_match(): No ending delimiter '.' found in C:\...\.php on line 194
Call Stack
#   Time    Memory  Function    Location
1   0.0024  397784  {main}( )   ..\lgrphoto.php:0
2   0.0035  402768  getphotos( )    ..\lgrphoto.php:522
3   0.9658  404688  preg_match ( )  ..\lgrphoto.php:194

第 194 行的函数:

function getphotos($photodir) {
    global $thumbext;
    $photos=array();
    if ($handle = opendir($photodir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && !preg_match(".jpg".$thumbext."$",$file) && preg_match(".jpg$",$file)){
                    $photos[] = $file;
            }
        }
        closedir($handle);
    }
    sort($photos);
    return $photos;
}

===========

完整代码:

<?php

/* Version .2.1.3 April 12, 2007

This script is written by Lee Robertson. Feel free to use it/modify it as you see fit. Use of this script as it our own risk. I make no guarantees that it will work on your machine/server. If something goes wrong, it is your responsibility not mine. You are not permitted to use this script for displaying any kind of pornography. Also if you use this script to make money in any way shape or form please consider a donation. Any amount is appreciated. I do have a two year old and a baby on the way to support. By using this script you also agree that I can link to your website.

For the latest version and bug fixes please visit photogallery.lgr.ca.

All that being said, this script is just a quick image gallery script that I wrote because I could find nothing out there that was as simple as just placing the script in the same folder as the images. The script should work on most servers that have PHP installed. It was developed on a Windows machine with Apache and PHP. A production version runs on a Linux machine with Apache and PHP.

If you like the script please either drop me a note at lee@lgr.ca or
even better a dollar or two (or more) via Paypal is always nice ;). 

If you would like this script modified to do something similar feel free to contact me. I am sure we can come to some arrangement. If you have other PHP work that you would like done, please drop me a note at lee@lgr.ca.

INSTALL
You can provide configuration varibles to change how the script works. If you don't tinker with any of the config variables it should work fine with the defaults.

Just place this script in the same folder as the JPEG images you want to have in your gallery.

If you want more albums, the script looks for images in subfolders below it, but it only does one level.
 For example:
 It will create galleries for all of the following folders:
 /photos -> Main album
 /photos/holidays ->Album
 /photos/cats ->Album

BUT not for the following folder:
 /photos/holidays/Saskatoon

The name of the subfolder automatically becomes the name of the album.

The first time you run the script it will create the thumbnails for you and create the gallery. If you ever want to change the size of the thumbnails just change the value in the script and it will recreate all o the thumbnails for you the next time you run the script.

**NOTE: Creating and recreating the thumbnails can take time. Please be patient. **

Simple eh!

Please leave this header alone.
*/


/* MY COMMENTS IN ALL CAPS. FUNCTION eregi() IS DEPRECATED USE preg_match() */


/* CONFIGURATION Title for your gallery that will be used with the default header. */
$title="LGR 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 extention 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;

/* 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 off.
//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";
$stylesheet="./styles/lgrphoto.css";
$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 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.";
            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 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 != ".." && !preg_match(".jpg".$thumbext."$",$file) && preg_match(".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="&amp;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."\">&lt;&lt; Previous</a>"; } else { $prev=""; }
        if (($photonum)<(count($photos))) { $next="<a href=\"".$_SERVER['PHP_SELF']."?pn=".$photonum.$query."\">Next&gt;&gt;</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,top=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="&amp;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 &gt;</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."\">&lt; 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)."&amp;p=".$photo."&amp;slide=1\">Start Slideshow</a>\n"; }
            else { $photobody[]="<a href=\"".$_SERVER['PHP_SELF']."?p=".$photo."&amp;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="&amp;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 &gt;</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."\">&lt; 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)."&amp;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="&amp;album=".urlencode($album); }
    if ($slide==1) { $query=$query."&amp;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;
?>
4

1 回答 1

1

您的错误出现了,因为您没有在表达式周围使用分隔符。例如,这个片段:

!preg_match(".jpg".$thumbext."$",$file) && preg_match(".jpg$",$file)

需要在表达式周围使用某种分隔符来显示它的开始和结束位置。这是一个使用波浪号作为分隔符的示例。请注意我放置的每个表达式的开头和结尾是如何放置的?

!preg_match('~\.jpg'.$thumbext.'$~', $file) && preg_match('~\.jpg$~', $file)

我还转义了句号,因为否则它将匹配任何字符并将双引号换成单引号。双引号内的美元符号被插入。

于 2016-01-13T23:04:52.933 回答