By default, Download Monitor stores uploaded files in the directory wp-content/uploads/dlm_uploads
. However, you may have specific requirements that necessitate a custom file upload path. In such cases, you can modify the default upload folder location by adding the following code snippet to your WordPress theme’s functions.php
file or your child theme’s functions.php
file.
Changing the Download Monitor Default Upload Folder Location
<?php
add_filter( 'upload_dir', 'change_upload_dir_for_dlm', 30 );
function change_upload_dir_for_dlm( $pathdata ){
if ( isset( $_POST['type'] ) && 'dlm_download' === $_POST['type'] ) {
if ( empty( $pathdata['subdir'] ) ) {
$pathdata['path'] = $pathdata['path'] . '/private';
$pathdata['url'] = $pathdata['url'] . '/private';
$pathdata['subdir'] = '/private';
} else {
$new_subdir = '/private' . $pathdata['subdir'];
$pathdata['path'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['path'] );
$pathdata['url'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['url'] );
$pathdata['subdir'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['subdir'] );
}
}
return $pathdata;
}
This code snippet allows you to customize the upload path for Download Monitor files. It checks if the uploaded file type is ‘dlm_download’ and, if so, updates the file path and URL to the ‘/private’ directory. If a subdirectory is present, it also appends ‘/private’ to it. This ensures that all Download Monitor files are stored in the specified ‘private’ directory.
Use Cases
This feature is particularly useful for servers that require files to be stored in a restricted folder to prevent direct access to them. For example, platforms like Pantheon utilize the wp-content/uploads/private
folder for private files to enhance security and access control.
By implementing this customization, you can seamlessly integrate Download Monitor with your server’s specific file storage requirements, enhancing the security and organization of your downloadable files.