Friday 17 October 2008 6:42:12 am
My suggestion to realize the download of a scaled image is the following: <b>1. My download link looks like this .../content/download/<contentobject_id>/<node_id>/<filename_of_the_relevant_image_alias></b> The filename of the relevant image alias could be for example: my_image_small.jpg
<b>2. Creating a new module with a customized binaryhandler (myfilepassthroughhandler.php)</b>
The determining function which has to be tuned is handleFileDownload. In this function the path to the scaled image has to be detected. This is the way I detect the path (replace the line "$fileName = $fileInfo['filepath'];"):
if( $contentObjectAttribute->DataTypeString == 'ezimage'){
$myPathInfoList = array_reverse( split( '/', $_SERVER['PATH_INFO'] ) );
$myObjectDataArray = $contentObjectAttribute->Content->ContentObjectAttributeData;
$myBasename = $myObjectDataArray['DataTypeCustom']['alias_list']['original']['basename'];
$myFilename = $myPathInfoList[0];
$myPostfixList = split( $myBasename, $myFilename );
$myAlias = splitFilename( $myPostfixList[1] );
$myFullPath = $myObjectDataArray['DataTypeCustom']['alias_list'][$myAlias]['full_path'];
$fileName = $myFullPath;
}
else {
$fileName = $fileInfo['filepath'];
}
The function splitFilename looks like this:
function splitFilename( $filename )
{
$pos = strrpos($filename, '.');
if ($pos === false)
{ // dot is not found in the filename
return 0; // no extension
}
else
{
$basename = substr($filename, 0, $pos);
$extension = substr($filename, $pos+1);
return ltrim( $basename, '_');
}
}
<b>3. Access to var-directory has to be limited via htaccess-file</b>
|