﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2622	Automatic dispatching of uploaded files to different folders	Ralph		"I suggest to add an option for automatic dispatching of uploaded files to different folders set in filemanager…config.php file according to the file type. For example, if an image is uploaded as 'FILE', it would be ﻿﻿nevertheless directed to the 'images' folder (if set) and if a new file type such as 'PDF' is created in config.php for file extension 'pdf' with a 'pdf_folder' destination folder, then FileUpload function would send it to this folder.

I patched my version successfully by easily adding just the following two lines of code in filemanager…command.php (and moving down a bit an original one).

Before:
{{{
	if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) )
	{
		global $Config ;

		$oFile = $_FILES['NewFile'] ;

		// Map the virtual path to the local server path.
		$sServerDir = ServerMapFolder( $resourceType, $currentFolder, $sCommand ) ;

		// Get the uploaded file name.
		$sFileName = $oFile['name'] ;
		$sFileName = SanitizeFileName( $sFileName ) ;

		$sOriginalFileName = $sFileName ;

		// Get the extension.
		$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
		$sExtension = strtolower( $sExtension ) ;

		if ( isset( $Config['SecureImageUploads'] ) )
		{
			if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false )
			{
				$sErrorNumber = '202' ;
			}
		}
}}}
After:
{{{
	if ( isset( $_FILES['NewFile'] ) && !is_null( $_FILES['NewFile']['tmp_name'] ) )
	{
		global $Config ;

		$oFile = $_FILES['NewFile'] ;

		// Get the uploaded file name.
		$sFileName = $oFile['name'] ;
		$sFileName = SanitizeFileName( $sFileName ) ;

		$sOriginalFileName = $sFileName ;

		// Get the extension.
		$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
		$sExtension = strtolower( $sExtension ) ;

		foreach($Config['ConfigAllowedTypes'] as $type) {	 // #PATCH: automatically dispatch uploaded files
			if($type != 'File' && in_array($sExtension, $Config['AllowedExtensions'][$type])) {
				$resourceType = $type;
			}
		}

		// Map the virtual path to the local server path. #PATCH: moved down
		$sServerDir = ServerMapFolder( $resourceType, $currentFolder, $sCommand ) ; // #HACK: original line moved down

		if ( isset( $Config['SecureImageUploads'] ) )
		{
			if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false )
			{
				$sErrorNumber = '202' ;
			}
		}
}}}
filemanager…config.php sample:
{{{
// Allowed Resource Types.
$Config['ConfigAllowedTypes'] = array('File', 'Image', 'Flash', 'Media', 'PDF') ;
…
$Config['AllowedExtensions']['File']	= array('7z', 'csv', 'doc', 'gz', 'gzip', 'ods', 'odt', 'ppt', 'pxd', 'rar', 'rtf', 'sdc', 'sitd', 'sxc', 'sxw', 'tar', 'tgz', 'txt', 'vsd', 'xls', 'xml', 'zip') ;
$Config['DeniedExtensions']['File']	= array() ;
$Config['FileTypesPath']['File']	= $Config['UserFilesPath'] . 'misc/' ;
…
$Config['AllowedExtensions']['Image']	= array('bmp','gif','jpeg','jpg','png') ;
$Config['DeniedExtensions']['Image']	= array() ;
$Config['FileTypesPath']['Image']	= $Config['UserFilesPath'] . 'images/' ;
…
$Config['AllowedExtensions']['Flash']	= array('swf','fla', 'flv') ;
$Config['DeniedExtensions']['Flash']	= array() ;
$Config['FileTypesPath']['Flash']	= $Config['UserFilesPath'] . 'flash/' ;
…
$Config['AllowedExtensions']['Media']	= array('aiff', 'asf', 'avi', 'mid', 'mov', 'mp3', 'mp4', 'mpc', 'mpeg', 'mpg', 'qt', 'ram', 'rm', 'rmi', 'rmvb', 'tif', 'tiff', 'wav', 'wma', 'wmv') ;
$Config['DeniedExtensions']['Media']	= array() ;
$Config['FileTypesPath']['Media']	= $Config['UserFilesPath'] . 'media/' ;
…
$Config['AllowedExtensions']['PDF']	= array('pdf') ;
$Config['DeniedExtensions']['PDF']	= array() ;
$Config['FileTypesPath']['PDF']		= $Config['UserFilesPath'] . 'pdf/' ;
}}}
"	New Feature	confirmed	Normal		General	FCKeditor 2.6.3		HasPatch	
