Results 1 to 1 of 1

Thread: PHP Photo Album script v2.11

  1. #1
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default PHP Photo Album script v2.11

    1) Script Title: PHP Photo Album script v2.11

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...photoalbum.htm

    3) Describe problem:
    Quote Originally Posted by php.net
    Note: As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this (eregi) function will issue an E_DEPRECATED notice. See the list of differences for help on converting to PCRE.
    link: http://us.php.net/manual/en/function.eregi.php

    Since preg_match is supported from PHP 4 on, the getalbumpics.php should be updated to, or at least be offered as an alternative - I suppose some folks are still stuck with PHP 3, but I wonder how well PHP 3 would do with the rest of the original code:

    PHP Code:
    <?php
    Header
    ("content-type: application/x-javascript");
    if (
    phpversion() >= 5.1){
       @
    date_default_timezone_set(date_default_timezone_get());
    }

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

    $photovar=$_GET['id'];
    if (!
    preg_match('/^[a-z_][a-z0-9_]+$/i'$photovar)){
        echo 
    'alert("Photo Album ID must contain only letters, numbers, or underscore, and cannot start with a number")';
        die();
    }
    echo 
    "var $photovar={\n";
    echo 
    "    baseurl: \"http://" $_SERVER["SERVER_NAME"] . dirname($_SERVER['PHP_SELF']) . "/\",\n";
    echo 
    "    images: [\n";
    returnimages();
    echo 
    "    ],\n";
    echo 
    "    desc: []\n";
    echo 
    "}\n";
    die();
    ?>
    Folks with PHP 5.3+ must use the above or else the script this supports will fail. And, as I say it's good for PHP 4+.

    Edit: I also have now added another die(); at the end. This will prevent those servers which automatically add tracking code and/or ads to the end of all served PHP pages from breaking the generated javascript code.


    Edit: Still later, added:

    Code:
    if (phpversion() >= 5.1){
       @date_default_timezone_set(date_default_timezone_get());
    }
    to deal with PHP 5.1+ systems with no date.time set.
    Last edited by jscheuer1; 07-05-2010 at 08:52 PM. Reason: add link for eregi function - later add die() at end - date.timezone fix
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •