Drupella File Manager for PHP ==================================== Version 1.0 REQUIREMENTS ----------- 1) A webserver (Apache, nginx, IIS) running PHP(preferably 5.3 or later) INSTALLATION ----------- 1) Copy dfm_php under your site directory so it is available at http://example.com/dfm_php (can change folder name) 2) Create a copy of the settings file "custom/default.settings.php" as "custom/settings.php" 3) Edit settings.php to set your managed files directory, admin password, and other configuration options. 4) Set settings.php as read-only! 4) Visit http://example.com/dfm_php and login as admin to manage your files. CKEditor Integration Methods ----------- 1- Set DFM as the default file browser in CKEditor's image & link dialogs. This requires to set "filebrowserBrowseUrl" parameter of CKEditor.config. http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.filebrowserBrowseUrl Either set it globally: CKEDITOR.config.filebrowserBrowseUrl = '/dfm_php?fileHandler=dfmCkeHandler'; Or set it per editor instance: CKEDITOR.replace('editor1', {filebrowserBrowseUrl: '/dfm_php?fileHandler=dfmCkeHandler'}); You also need to define the handler(dfmCkeHandler) by javascript in the page on which CKEditor is being displayed: // File handler that is called by DFM when a file is selected window.dfmCkeHandler = function(selectedFile, dfmWindow) { CKEDITOR.tools.callFunction(dfmWindow.dfm.urlParam('CKEditorFuncNum'), selectedFile.getUrl()); dfmWindow.close(); }; 2- Use the CKEditor plugin provided in wysiwyg_plugins/ckeditor The plugin introduces new image(DfmImage) & link(DfmFile) buttons that allow inserting multiple files at once. Either introduce the plugin to CKEditor as an external plugin: CKEDITOR.plugins.addExternal('dfm', '/dfm_php/wysiwyg_plugins/ckeditor/', 'plugin.js'); Or copy wysiwyg_plugins/ckeditor as /plugins/dfm Then use it in editor configuration CKEDITOR.replace('editor1', { extraPlugins: 'dfm', toolbar : [['Bold', 'Italic', 'Underline', 'DfmImage', 'DfmFile']] }); Note: You may want to update the plugin.dfmUrl = '/dfm_php' setting in the plugin.js file. In that case move the plugin to a custom folder to prevent overwriting on next update. TinyMCE Integration Methods ----------- 1- Set DFM as the default file browser in TinyMCE's image & link dialogs. This requires to set "file_browser_callback" parameter in editor config. http://www.tinymce.com/wiki.php/Configuration:file_browser_callback tinymce.init({ selector: "#mytextarea", file_browser_callback: function(fieldId, url, type, win) { var dfmUrl = '/dfm_php'; if (win && win.open) { dfmUrl += (dfmUrl.indexOf('?') == -1 ? '?' : '&') + 'urlFieldId=' + encodeURIComponent(fieldId); win.open(dfmUrl, '', 'width=800,height=520,resizable=1'); } } }); 2- Use the TinyMCE plugin provided in wysiwyg_plugins/tinymce. The plugin introduces new image(DfmImage) & link(DfmFile) buttons that allow inserting multiple files at once. Either include the plugin.js in the page after tinymce.js Or copy wysiwyg_plugins/tinymce as /plugins/dfm Then use it in editor configuration tinymce.init({ selector: 'textarea', plugins: 'dfm', toolbar: 'dfm' }); Note: You may want to update the plugin.dfmUrl = '/dfm_php' setting in the plugin.js file. Custom Application Integration ----------- 1) In your js file(or page), define a file handler for DFM to call. Ex: window.myDfmFileHandler = function(File, dfmWindow) { // Get some file properties var url = File.getUrl(), name = File.name, size = File.size, date = File.date, safeName = File.formatName(), formattedSize = File.formatSize(), formattedDate = File.formatDate(); // Do something using the file properties. Ex: populate an url input $('#my-url-input').val(url); // Close the file manager window dfmWindow.close(); }; 2) Open the file manager in a new window/iframe with the url "/dfm_php?fileHandler=myDfmFileHandler". Ex: window.open('/dfm_php?fileHandler=myDfmFileHandler', '', 'width=800,height=520,resizable=1'); It can also be triggered by a link: Open File Manager 3) That's all. The rest will be handled by DFM. myDfmFileHandler will be called when a file is selected. Embed DFM Into a Page ----------- 1) As an iframe 3) As a dynamic element loaded into a wrapper element.
Integrate DFM into Your CMS, Framework, or Custom Site ----------- 'my-files', // Root directory URL that will be used to create file URLs. // No default. Required 'rootDirUrl' => 'http://example.com/my-site/my-files', // Relative path to DFM library from the running script. // No default. Required. 'scriptDirPath' => 'dfm_php/library', // The base URL of the running script. Either absolute or relative to the domain(starting with a / character) // No default. Required. 'baseUrl' => '/my-site', // Security key that is required against CSRF attacks. // Must be unique to the user session. // Ex: md5(session_id()) // No default. Required. 'securityKey' => '', // Available directories for the current user. /* Ex: // Enable access to with all possible permissions array( '.' => array( 'perms' => array('all' => 1), 'subdirConf' => array('inherit' => 1), ), ); // Enable access to /user-folder with specific permissions array( 'user-folder' => array( 'perms' => array( 'listFiles' => 1, 'listFolders' => 1, 'uploadFiles' => 1, 'createFolders' => 1, 'deleteFiles' => 1, 'deleteFolders' => 1, 'moveFiles' => 1, 'moveFolders' => 1, 'copyFiles' => 1, 'copyFolders' => 1, 'renameFiles' => 1, 'renameFolders' => 1, 'downloadFiles' => 1, 'downloadFolders' => 1, 'resize' => 1, 'crop' => 1, ), 'subdirConf' => array( 'inherit' => 1, // Sub-folders inherit parent permissions ), ), ); // Multiple folder assignment + Different permissions for parent and child folders array( 'user-folder' => array( 'perms' => array( 'listFiles' => 1, 'listFolders' => 1, ), 'subdirConf' => array( 'perms' => array( 'listFiles' => 1, 'uploadFiles' => 1, 'deleteFiles' => 1, ), ), ), 'another-folder' => array( 'perms' => array( 'listFiles' => 1, ), ) ); */ 'dirConf' => array( '.' => array( 'perms' => array('all' => 1), 'subdirConf' => array('inherit' => 1), ), ), // Maximum upload size in bytes. // Should not exceed PHP's upload_max_size directive. // Ex: '10M' or 10485760, 0(Unlimited) // Default: '2M' 'uploadMaxSize' => 0, // A list of allowed file extensions to upload. // Can be provided as an array or a string(separate extensions by a space character) // Ex: array('*') OR '*' (All files), array('txt', 'html') OR 'txt html' (Text and html documents) // Default: NULL (Upload disabled) 'uploadExtensions' => array('*'), // Executable extensions that will be converted to txt on upload for security reasons. // Ex: array('php') will make foo.php uploaded as foo.php.txt // Default: array('php', 'pl', 'py', 'cgi', 'asp', 'js') 'execExtensions' => array('php', 'pl', 'py', 'cgi', 'asp', 'js'), // Allow upload of files with an executable extension or files without an extension. // Note: Enabling this configuration is a security risk. // Default: 0 'uploadInsecure' => 0, // File extensions that will be treated as images. // Ex: array('jpg') (Jpeg only), FALSE (Disable image operations) // Default: array('jpg', 'jpeg', 'png', 'gif') 'imgExtensions' => array('jpg', 'jpeg', 'png', 'gif'), // Maximum allowed image dimensions during upload or image operations. // Ex: '800x600' // Default: 0 (Unlimited) 'imgMaxDim' => 0, // Allow upscaling of images. // Default: 0 'imgUpscale' => 0, // Allow working on a copy during image operations regardless of the file copy permission. // Default: 0 'imgCopy' => 1, // Jpeg quality in image operations. // Default: 85 'imgJpegQuality' => 85, // Skip scaling of images to allowed dimensions on upload. // The ones exceeding the allowed dimensions will be rejected. // Default: 0 (Images are scaled down to allowed dimensions) 'uploadNoScale' => 1, // Allowed extensions in rename operation. // Ex: array('txt', 'html', 'css') // Default: NULL (Use uploadExtensions) 'renameExtensions' => NULL, // Allow changing the file extension in rename operation. // Default: 0 'renameExtensionAlter' => 0, // Maximum file length allowed. // Default: 255 'maxFileLength' => 255, // Enable file searching. // Default: 0 'searchOn' => 1, // Limit number of search results for performance reasons. // Default: 0 (Unlimited) 'searchLimit' => 0, // Prefix added to copied file names. // Ex: 'Copy of ' // Default: '' 'copyNamePrefix' => '', // Suffix added to copied file names. // Default: ' - Copy' 'copyNameSuffix' => ' - Copy', // Default mode for newly created directories // Default: 0775 'directoryMode' => 0775, // Default mode for newly created files // Default: 0664 'fileMode' => 0666, // Show PHP errors to users. // Default: 0 'displaySystemErrors' => 0, // Show root directory path to the user in file manager's status bar // Default: 0 'exposeRootDirPath' => 0, // Filter out files that start/end with a dot, e.g .htaccess // Default: 1 'filterDotFiles' => 1, // Filter out files with a unicode name. // This is enabled on Windows by default as PHP-Win can not handle unicode filenames. // Default: NULL (1 on Windows) 'filterNonAscii' => NULL, // A list of regular expressions to match file names to filter out. // Ex: array('^foo', '\.bar$') filters file names starting with 'foo' or ending with '.bar' // Default: array() (No filtering) 'filterRegExps' => array(), // Apply double URL encoding for # and & characters while creating file URLs // Enable if your webserver has some URL rewrite rules decoding these characters before sending to the script. // Default: 0 'urlRewrite' => 0, // Added to dynamically included js/css file URLs to allow fresh loading of files on updates. // Default: '' 'jsCssSuffix' => '', // Enabled plugin names. // Ex: array('FOO') (dfm_FOO_plugin_register(Dfm $dfm) will be called before DFM executes) // Default: array() (No custom plugins) 'plugins' => array(), // Custom theme name. // Default: NULL (Use base theme) 'theme' => NULL, // Custom UI language. // Language file library/i18n/dfm.LANG.js will be included if it exists. // Default: NULL (English) 'lang' => 'en', // String translations/overrides. // These translations will override the ones included in dfm.LANG.js. // library/i18n/dfm.template.js contains all translatable strings. // Ex: array( // 'Refresh' => 'Reload', // 'Complete' => 'Done', // ); // Default: NULL 'i18n' => NULL, // Base URL for thumbnails. // If provided, image icons will be displayed as thumbnails pointing to thumbUrl/[relative image path] // For /foo/bar.jpg the thumbnail url will be thumbUrl/foo/bar.jpg // Note: DFM does not create the thumbnails itself. // It assumes the resulting path is handled with a script that generates the image derivatives // Default: NULL 'thumbUrl' => NULL, // Apply double URL encoding for # and & characters to thumbnail URLs // Enable if your webserver has some URL rewrite rules decoding these characters before sending to the script. // Default: 0 'thumbUrlRewrite' => 0, // SWF Authentication parameters. // If provided, DFM will enable swf(Flash) upload for old browsers that do not support html5. // Flash uses a different session than the browser and requires a separate authentication. // Ex: array('user_id' => 1, 'token' => 'fc38808a1a77c7483dc05d9d46f5453f') // Note: DFM does not perform the authentication itself. // It assumes the integrating script handles the authentication. // Default: NULL 'swfAuth' => NULL, // Scheme for the current file stream wrapper. // If the root directory uses a custom stream wrapper you can pass the stream name to the client for custom use. // Ex: temporary (for temporary://my_files as the root) // Default: NULL 'scheme' => NULL, ); ?> run(); } // Not a js request. Print the page(or content block) that loads DFM. else { // An example standalone page where DFM js/css is included in head and the UI is loaded under body element // Note: dfm.js requires jQuery(any version). This example uses the one included in the library. print ' File Manager '; exit; } } ?>