Sometimes it may be useful to keep original image files and DAlbum generated files (image thumbnails,
.albumdef.ini files etc.) in separate folders.
In this sample original images are stored in ./pictures directory, and all generated files in
./generated directory. For example, thumbnail for ./pictures/myfolder/myfile.jpg will be stored in
./generated/myfolder/myfile.jpg. This way ./pictures directory can be read-only.
This functionality is achieved by overriding customAbsfname function that converts image path relative
to ./pictures directory (ex. /myfolder/myfile.jpg) to filename (./pictures/myfolder/myfile.jpg or
/home/john/public_html/pictures/myfolder/myfile.jpg). Additional steps are made to ensure that
.htaccess files are created in ./generated directory as well.
Instructions
1. Edit you custom.php and add
the following code. Modify $g_sGeneratedRoot and $g_sGeneratedRootBrowser variables to point
to correct directories. These variables are have similar meaning to $g_sAlbumsRoot and $g_sAlbumsRootBrowser, which
are described in Securing DAlbum installation.
| // Folder with generated images and .albumdef.ini files
$g_sGeneratedRoot="./generated";
// This is used with direct image access
$g_sGeneratedRootBrowser=dirname_ex($g_sAlbumsRootBrowser) . "/generated";
// returns true if $filename resides under $g_sGeneratedRoot folder
function IsGeneratedLocation($name)
{
global $g_sThumbnailPath, $g_sResizedPath;
// If you prefer to store .albumdef.ini file in the same folder
// with original images, comment or remove line
//
// basename(strval($name))==".albumdef.ini" ||
//
// below.
if ( strstr($name,'/' . $g_sThumbnailPath . '/') ||
substr($name,-strlen($g_sThumbnailPath))==$g_sThumbnailPath ||
strstr($name,'/' . $g_sResizedPath . '/') ||
substr($name,-strlen($g_sResizedPath))==$g_sResizedPath ||
basename(strval($name))==".albumdef.ini" ||
getext($name)=='cmt' )
return true;
return false;
}
// override URL generation for direct access. Produces
// http://mysite.com/photo/generated/_thm/thm_pic1.jpg
// instead of
// http://mysite.com/photo/pictures/_thm/thm_pic1.jpg)
// for generated images
function customURL($picPath)
{
global $g_bHTTPAuth, $g_bDirectAccess, $g_sAlbumsRootBrowser;
global $g_sGeneratedRootBrowser;
if ($g_bDirectAccess && substr(basename(strval($picPath)),0,1)!='.')
{
if ($g_bHTTPAuth || !isset($_SESSION['UID']))
{
if (IsGeneratedLocation($picPath))
return quoteurl($g_sGeneratedRootBrowser . $picPath);
return quoteurl($g_sAlbumsRootBrowser . $picPath);
}
}
return 'photo.php?file=' . quoteurl($picPath);
}
// Handle conversion from relative filename to absolute
function customAbsfname($name)
{
global $g_sAlbumsRoot, $g_sGeneratedRoot;
if (IsGeneratedLocation($name))
return $g_sGeneratedRoot . $name;
return $g_sAlbumsRoot . $name;
}
class CExAlbumGenerated extends CAlbum
{
function Create($sPath, $parentUsers,$bCleanup, $bDeleteImages=false)
{
// Create a corresponging folder in "generated" tree
global $g_sGeneratedRoot,$g_sAlbumsRoot;
if ($g_sGeneratedRoot!=$g_sAlbumsRoot)
{
if (!checkDirectory($g_sGeneratedRoot.$sPath))
{
global $g_newDirRights;
dalbum_mkdir($g_sGeneratedRoot.$sPath,$g_newDirRights);
}
}
// Call default implementation
if (!parent::Create($sPath,$parentUsers,$bCleanup,$bDeleteImages))
return false;
// Create .htaccess in generated folder too
if ($g_sGeneratedRoot!=$g_sAlbumsRoot)
{
if (join(",",$parentUsers)==join(",",$this->m_arrUsers))
delete_htaccess($g_sGeneratedRoot.$this->m_sFolder);
else
create_htaccess($g_sGeneratedRoot.$this->m_sFolder,$this->m_arrUsers);
}
return true;
}
}
function &customCreateAlbum()
{
return new CExAlbumGenerated();
} |
2. Create the directory set in $g_sGeneratedRoot (./generated by default) and CHMOD it to 777.
3. Reindex. Generated files are be now stored in the new folder.
|