[TYPO3-templavoila] FCE File-Download

Bart Veldhuizen [V-INT] bart at v-int.nl
Fri May 25 07:39:33 CEST 2007


Hi Jens,

I've done the same thing a few weeks ago:

http://www.zonmw.nl/nl/programma-s/alle-programma-s/diabetes- 
ketenzorg/actueel/

I created an FCE that contains a section with download link  
containers. Next, I'm using a userFunc to determine both the file's  
class (for displaying the right icon) and its filesize in KB or MB  
for each file in the section. The TV XML contains the following TS  
code; it passes the file information to a custom PHP script:

<TypoScript><![CDATA[
	10 = COA
	10 {

		10 = TEXT
		10 {
			field = field_download_file
			postUserFunc = user_get_fileclass
			wrap = <li class="|">
		}

		20 = TEXT
		20 {
			field  = field_download_title
			typolink.parameter.field = field_download_file
		}

		30 = TEXT
		30 {
			field = field_download_file
			postUserFunc = user_get_filedesc
		}	
		
		40 = TEXT
		40.value = </li>

	}
	
]]></TypoScript>



Here's the user functions file in case you're interested:



<?
	/***
	 *
	 */
	function user_get_fileclass($strUrl, $arrOpt)
	{
		// bepaal extensie
		$strExt = strrchr( $strUrl, '.' );
		$strExt = strtolower( $strExt );
		$strExt = substr( $strExt, 1 );
		
		return( $strExt );
	}
	

	function user_get_filedesc($strUrl)
	{
		// bepaal filesize
		$strDocRoot = '<ENTER YOUR DOCROOT HERE>';

		$strFile = $strDocRoot . $strUrl;
		$strFile = urldecode( $strFile );
				
		$intFileSize = filesize( $strFile );
		
		if( $intFileSize < 1024*1024 ) {
			$intFileSize = (int)$intFileSize / 1024;
			$strFileSizeIndicator = 'KB';
		} else {
			$intFileSize = (int)$intFileSize / (1024*1024);
			$strFileSizeIndicator = 'MB';
		}
		
		// tot 1 cijfer achter de comma
		$intFileSize = round( $intFileSize, 1 );
		
		// bepaal extensie
		$strExt = strrchr( $strUrl, '.' );
		$strExt = strtoupper( $strExt );
		$strExt = substr( $strExt, 1 );
		
		$strResult = "Size $intFileSize $strFileSizeIndicator ($strExt)";
		return( $strResult );
	}
?>


Op 24-mei-2007, om 23:24 heeft Jens Schmietendorf het volgende  
geschreven:

> Hi list!
> I have a FCE that shows a small list with files for downloading.I  
> need the filesize for the selected file as additional info in  
> FE.The mapping is not the problem,but i don´t found a way to  
> automatically generate the filesize info.At the moment I use a pure  
> text input field for the filesize, but that´s not good.
> So I need a USER object,but how can I transform the current  
> filename into that USER object?
> The only possible way I can see ist to use  
> register:tx_templavoila_pi1.parentRec.uidto get the tt_content -  
> uid into the USER object,parse the tx_templavoila_flex - field and  
> get my filename and filesize($absPath_to_filename) to return it.
> Is there an other simple solution for the problem?
> greetings from  
> Swedenjenses_______________________________________________TYPO3- 
> project-templavoila mailing listTYPO3-project- 
> templavoila at lists.netfielders.dehttp://lists.netfielders.de/cgi-bin/ 
> mailman/listinfo/typo3-project-templavoila

------------------------------------------------------------------------ 
--
Bart Veldhuizen, Veldhuizen Interactive.  Tel: 06-420 67 330
website analyse & advies | content management systemen




More information about the TYPO3-project-templavoila mailing list