Opened 16 years ago
Last modified 16 years ago
#2622 confirmed New Feature
Automatic dispatching of uploaded files to different folders
Reported by: | Ralph | Owned by: | |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | General | Version: | FCKeditor 2.6.3 |
Keywords: | HasPatch | Cc: |
Description
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/' ;
Attachments (2)
Change History (6)
comment:1 Changed 16 years ago by
Changed 16 years ago by
Attachment: | commands.patch added |
---|
fckeditor_263/editor/filemanager/connectors/php/commands.php
Changed 16 years ago by
Attachment: | config.patch added |
---|
fckeditor_263/editor/filemanager/connectors/php/config.php
comment:2 Changed 16 years ago by
I uploaded the requested patchs hopping I used the right diff options. Added in the meanwhile a $Config selector for enabling/disabling the dispatching option.
Thanks mosipov for your help :)
comment:3 Changed 16 years ago by
Keywords: | HasPatch added |
---|
comment:4 Changed 16 years ago by
Keywords: | Confirmed added |
---|
Please provide rather a diff file than 2 code fragments.