Results 1 to 9 of 9

Thread: Need Help with PHP Photo Album Script

  1. #1
    Join Date
    Dec 2005
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need Help with PHP Photo Album Script

    Hi world!

    I am using the PHP Photo Album Script found on this site - DynamicDrive. This script allows the php to grab files in a particular folder and display them on the screen. Now here's the problem . . . it says that it will display the images by FILE NAME and also has the feature to display by DATE. I followed the instructions to display by FILE NAME, but it is not working. It keeps displaying the images by the date not the file name. I NEED IT BY FILE NAME!!

    Can anyone debug this thing? Here's the script:

    HTML:
    <HEAD>
    <style type="text/css">

    .slideshow{ /*CSS for DIV containing each image*/
    float: left;
    margin-right: 11px;
    margin-bottom: 10px;
    }

    .slideshow img{ /*CSS for each image tag*/
    border: 0;
    width: 135x;
    height: 88px;
    }

    #navlinks{ /*CSS for DIV containing the navigational links*/
    width: 400px;
    }

    #navlinks a{ /*CSS for each navigational link*/
    margin-right: 0px;
    margin-bottom: 05px;
    font-size: 100%;
    }

    #navlinks a.current{ /*CSS for currently selected navigational link*/
    background-color: #C6E959;
    }
    </style>
    </HEAD>
    -------------------------------------------------------------------
    ---------------------------------------------------------------------

    <BODY>
    <script type="text/javascript">

    /***********************************************
    * PHP Photo Album script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
    * This notice must stay intact for legal use
    ***********************************************/

    var dimension="4x5" //Specify dimension of gallery (number of images shown), such as 4x2, 3x1 etc
    var imagepath="http://www.clientcardz.com/Layouts_Small/" //Absolute path to image directory. Include trailing slash (/)
    var href_target="new" //Enter target attribute of links, if applicable

    //Toggle popup link setting: popupsetting[0 or 1, "pop up window attributes" (if 1)]
    var popupsetting=[1, "width=440px, height=275px, scrollbars, resizable"]

    //Toggle image description: descriptionprefix[0 or 1, "Text to show" (if 1)]
    var descriptionprefix=[1, "Layouts-"]

    //Sort images by date? ("asc", "desc", or "")
    //"desc" for example causes the newest images to show up first in the gallery
    //"" disables this feature, so images are sorted by file name (default)
    var gsortorder=""

    //By default, each image hyperlinks to itself.
    //However, if you wish them to link to larger versions of themselves
    //Specify the directory in which the larger images are located
    //The file names of these large images should mirror those of the original
    //Enter a blank string ("") to disable this option
    var targetlinkdir="http://www.clientcardz.com/Layouts_Large/"

    /////No need to edit beyond here///////////////////

    function sortbydate(a, b){ //Sort images function
    if (gsortorder=="") //sort by file date: older to newer
    return new Date(a[1])-new Date(b[1])
    else if (gsortorder=="") //sort by file date: newer to older
    return new Date(b[1])-new Date(a[1])
    }

    if (gsortorder=="" || gsortorder=="")
    galleryarray.sort(sortbydate)

    var totalslots=dimension.split("x")[0]*dimension.split("x")[1]

    function buildimage(i){
    var imagecompletepath=(targetlinkdir!="")? targetlinkdir+galleryarray[i][0] : imagepath+galleryarray[i][0]
    var tempcontainer='<a href="'+imagecompletepath+'" target="'+href_target+'" onClick="return popuplinkfunc(this)">'
    tempcontainer+='<img src="'+imagepath+galleryarray[i][0]+'" title="'+galleryarray[i][0]+' ['+galleryarray[i][1]+']" />'
    tempcontainer+='</a><br />'
    tempcontainer+=(descriptionprefix[0]==1)? descriptionprefix[1]+(i+1) : ""
    return tempcontainer
    }

    function jumptopage(p){
    var startpoint=(p-1)*totalslots
    var y=1;
    for (i=0; i<totalslots; i++){
    document.getElementById("slide"+i).innerHTML=(typeof galleryarray[startpoint+i]!="undefined")? buildimage(startpoint+i) : ""
    }
    while(document.getElementById("navlink"+y)!=null){
    document.getElementById("navlink"+y).className=""
    y++
    }
    document.getElementById("navlink"+p).className="current"
    }

    var curimage=0
    for (y=0; y<dimension.split("x")[1]; y++){
    for (x=0; x<dimension.split("x")[0]; x++){
    if (curimage<galleryarray.length)
    document.write('<div id="slide'+curimage+'" class="slideshow">'+buildimage(curimage)+'</div>')
    curimage++
    }
    document.write('<br style="clear: left" />')
    }

    function popuplinkfunc(imgsrc){
    if (popupsetting[0]==1){
    var popwin=open(imgsrc.href, "popwin", popupsetting[1])
    popwin.focus()
    return false
    }
    else
    return true
    }

    </script>

    <!--Below HTML code refers to the navigational links for the gallery-->

    </font>

    <div id="navlinks">
    <font face="Arial" size="2" color="#354600">
    <script type="text/javascript">
    for (i=1; i<Math.ceil(galleryarray.length/totalslots)+1; i++)
    document.write('<a id="navlink'+i+'" href="javascript:jumptopage('+i+')\"><img border="0" src="http://www.clientcardz.com/Lanitech_Artwork/graphic_arrow_blue.gif" width="11" height="11">Page '+i+' </a> ')
    document.getElementById("navlink1").className="current"
    </script>
    </BODY>
    ----------------------------------------------------------------------
    ---------------------------------------------------------------------

    PHP SCRIPT:

    <?
    Header("content-type: application/x-javascript");

    function returnimages($dirname=".") {
    $pattern="\.(jpg|jpeg|png|gif|bmp)$";
    $files = array();
    $curimage=0;
    if($handle = opendir($dirname)) {
    while(false !== ($file = readdir($handle))){
    if(eregi($pattern, $file)){
    $filedate=date ("M d, Y H:i:s", filemtime($file));
    echo 'galleryarray[' . $curimage .']=["' . $file . '", "'.$filedate.'"];' . "\n";
    $curimage++;
    }
    }

    closedir($handle);
    }
    return($files);
    }

    echo "var galleryarray=new Array();" . "\n";
    returnimages();
    ?>
    -----------------------------------------------------------------------
    ----------------------------------------------------------------------
    You can see it in action here:

    http://www.clientcardz.com/layouts.htm


    HELP PLEASE!!! SOMEONE!!

  2. #2
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    It looks correct to me. Have you already fixed this?

  3. #3
    Join Date
    Dec 2005
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default No

    I thought it looked fine too! This is the script right now as we speak - live on their web site. It's not been touched since I posted this thread.

    I followed the instructions in the script and it doesn't work. Go to this link and you will see that it is not sorting by file name. Try mouseing over the images on PAGE 3 <- important, and you'll see the error.

    http://www.clientcardz.com/layouts.htm

    PS thanks for responding. Cool!

  4. #4
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    I still don't see. Yes it adds the date/time, but it is still sorting by filename.

  5. #5
    Join Date
    Dec 2005
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ok, check it out . . .

    Go to Page 3 and look at the image with the light house and water which is presently labeled "layouts-47". Then mouseover the image or right click/properties the image and you'll see that the image's real name is layout_53.jpg which is out of order.

    http://www.clientcardz.com/layouts.htm

  6. #6
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Ok, I see your error now.
    Code:
    function sortbydate(a, b){ //Sort images function
    if (gsortorder=="") //sort by file date: older to newer
    return new Date(a[1])-new Date(b[1])
    else if (gsortorder=="") //sort by file date: newer to older
    return new Date(b[1])-new Date(a[1])
    }
    
    if (gsortorder=="" || gsortorder=="")
    galleryarray.sort(sortbydate)
    to
    Code:
    function sortbydate(a, b){ //Sort images function
    if (gsortorder=="asc") //sort by file date: older to newer
    return new Date(a[1])-new Date(b[1])
    else if (gsortorder=="desc") //sort by file date: newer to older
    return new Date(b[1])-new Date(a[1])
    }
    
    if (gsortorder=="asc" || gsortorder=="desc")
    galleryarray.sort(sortbydate)

  7. #7
    Join Date
    Dec 2005
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sorry, Didn't work

    Hi again,

    I replaced the script as you indicated and now it is more crazy than ever! I've created a new page so you can see what's going on.

    http://www.clientcardz.com/layouts_03.htm

    If you look at Page 1, the first image (with the water and lighthouse) you will see that it is labeled "layouts-01" but when you mouseover/right click properties it is actually "layout_53.jpg" which should be towards the end of images (Page 3). It's still be sorted by date/time not file name or this file would be at the end.

  8. #8
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    I think you may have more errors in your copying of the script. Start from scratch with the script exactly how it is on Dynamic Drive

  9. #9
    Join Date
    Dec 2005
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks again, but already did that

    Hi again,

    I already started over from scratch way before I posted on this forum. I am an experienced and advanced web designer and if I'm asking the forums, then I'm in big trouble!

    Still not working.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •