1.44 build 177
Please rate DAlbum at HotScripts.com
Please rate DAlbum at @ PHP-Resource.de
Rate DAlbum @ The PHP Resource Index
Script Rating:
FAQ   
  1. How to order images and galleries?
  2. How to disable creation of resized images?
  3. How to set folder title image without displaying the image inside?
  4. How to configure DAlbum to use ImageMagick on Microsoft IIS?
  5. How to use NetPBM for image resizing?
  6. How to prevent direct image linking (hot linking)

How to order images and galleries?

Albums and images are sorted alphabetically by their filenames. For example, images "first.jpg", "Second.jpg", "Third.jpg" and "Fourth.jpg" will be sorted as follows:

  1. Fourth.jpg
  2. Second.jpg
  3. Third.jpg
  4. first.jpg

To change the order of images, rename them as 001-first.jpg, 002-Second.jpg, 003-Third.jpg and 004-Fourth.jpg correspondingly. There are many utilities available which can simplify the renaming process - check Batch Renaming.

To hide the leading digits from your users without manually editing every image caption in .albumdef.ini, uncomment and modify filename2title function in your custom.php file as follows:

function filename2title($filename)
{
    return ereg_replace( "^[0-9]+-", "", getfname($filename) );
}
This way your album users will see your images as "first", "Second", "Third" and "Fourth" and in appropriate order.

You can also define your own sorting method by overriding CAlbum::Sort method in derived class.

This example adds DescendingOrder custom field to albums. When it is set to "1" in album properties, album contents will be sorted in descending order:

 class CExAlbumSortOrder extends CAlbum
{
    
// Get list of custom field names
    
function &GetCustomFieldNames()
    {
        
$f=parent::GetCustomFieldNames();
        
$f[]="DescendingOrder";
        return 
$f;
    }

    function 
cmpAlbDesc($a$b)
    {
        if (
$a->IsImage())
        {
            if (
$b->IsImage())
                return -
strcasecmp($a->m_sBaseFilename$b->m_sBaseFilename);
            return 
1;
        }
        if (
$b->IsImage())
            return -
1;

        return -
strcasecmp(basename(substr($a->m_sFolder,0,-1)),
                           
basename(substr($b->m_sFolder,0,-1)));
    }

    function 
Sort()
    {
       if (
$this->GetCustomField("DescendingOrder")>0)
          
usort($this->m_arrContents,array(get_class($this),"cmpAlbDesc"));
       else
          
usort($this->m_arrContents,array(get_class($this),"cmpAlb"));
    }
}

function &
customCreateAlbum()
{
    return new 
CExAlbumSortOrder();
}

How to disable creation of resized images?

DAlbum does not create a resized image if the original image is smaller than resized image size. Edit your config.php file and set

$g_sResizedXSize=50000;
$g_sResizedYSize=50000;

How to configure DAlbum to use ImageMagick on Microsoft IIS

  1. Set
    $g_sResizeMethod="IM";
    in config.php
  2. Edit $g_sConvertPath variable in config.php and set it to location where ImageMagick is installed. For example
    $g_sConvertPath="c:/ImageMagick/convert.exe";
    Remember to replace all backslashes with forward slashes.
  3. You need to give IIS user account access rights to your C:\WINNT\SYSTEM32\Cmd.exe. The best way to do it is go to your IIS Admin, select reindex.php and set it to run as another user (not IUSR_xxx). More secure solution would be to disable anonymous access to reindex.php completely and set authentication on. Then you will be asked for username and password for Windows account every time you reindex the photo album.
  4. In order to run DAlbum test you will need to configure test.php account the same way as reindex.php in step 3.
  5. Ensure that temp directory is writeable by the same account.

How to set folder title image without displaying the image inside?

Create a file named:

  • .folder.jpg
  • .folder.gif
  • .folder.png
  • _folder.jpg
  • _folder.gif
  • _folder.png

inside your folder. This file should be smaller or equal to your configured thumbnail size (default 128x128 pixels).

How to use NetPBM for image resizing?

If your host has NetPBM graphics software package installed, you can use it to create thumbnails and resized images:

  1. Download and extract rsnetpbm.pl from rsnetpbm.zip into DAlbum root directory. You may need to edit this file and set directory where NetBMP package is installed. CHMOD rsnetpbm.pl to be not executable (ex. 444).
  2. Edit your config.php file as follows:
     // Force command-line image resizing</span>
    $g_sResizeMethod="IM";

    ...

    // Change it to location of your Perl interpreter if necessary</span>
    $g_sConvertPath="/usr/bin/perl";
    $g_sThumbnailImArg="$g_sConvertPath ./rsnetpbm.pl #src# #target# ".
                         
    "$g_sThumbnailQuality $g_sThumbnailXSize $g_sThumbnailYSize";
    $g_sResizedImArg  ="$g_sConvertPath ./rsnetpbm.pl #src# #target# ".
                         
    "$g_sResizedQuality $g_sResizedXSize $g_sResizedYSize";
  3. Reindex.

Using a similar approach any command-line image resizing toolkit can be used with DAlbum.

How to prevent direct image linking (hot linking)

As your public images can be accessed by using a URL (ex. www.mysite.com/photo/photo.php?file=/folder1/test.jpg), your site may become subject to direct linking. This happens when somebody posts URL of your image on another site or forum and hundreds of people suck your bandwidth without even visiting your site.

To disable direct linking to your images, edit your config.php and ensure that the following variables are set as follows:

$g_bDirectAccess=false;
...
$g_bHTTPAuth=false;

This way DAlbum code is called every time an image is downloaded.

Then add the following code snippet to custom.php:

 DisableDirectLinking();

function 
DisableDirectLinking()
{
    
$ip=$_SERVER['REMOTE_ADDR'];
    if (@
$_SERVER["HTTP_X_FORWARDED_FOR"])
        
$ip=$_SERVER["HTTP_X_FORWARDED_FOR"];
    
$sCookieValue=md5($_SERVER['HTTP_HOST'].$ip);

    if (
stristr($_SERVER['PHP_SELF'],"photo.php"))
    {
        if (!isset(
$_COOKIE['DAlbum_Connection']) ||
             
$_COOKIE['DAlbum_Connection']!=$sCookieValue)
        {
            
// Check referrer. If referrer is our domain -
            // allow access even if cookie is not set
            
if (isset($_SERVER['HTTP_REFERER']))
            {
                
$ref=parse_url($_SERVER['HTTP_REFERER']);
                
$sHost=basename($ref['host'] );
                if (isset(
$_SERVER['HTTP_HOST']) &&
                    
strcasecmp($_SERVER['HTTP_HOST'],$sHost)==0)
                    return;
            }
            
hdr("404 Not found");
            exit();
        }
    }
    else
    {
        
// Set cookie for one hour.
        
setcookie("DAlbum_Connection",$sCookieValue,time()+3600);
    }
}

This code forces all DAlbum pages except photo.php to set a one-hour cookie on every visit. If there is a direct link to photo.php, the cookie will not be set and "404 Page not found" error returned to client. Page referer check is also performed to enable users with disabled cookies to browse your site.