Title: Custom dynamic prefix
Last modified: November 30, 2018

---

# Custom dynamic prefix

 *  Resolved [christophekonig](https://wordpress.org/support/users/christophekonig/)
 * (@christophekonig)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/custom-dynamic-prefix/)
 * Hello,
 * Thank you for your great plugin, it is awesome.
 * Do you know of any way that we could define our own dynamic prefixes ?
 * I see, in the “Prefixer” Class, that there is some string replacement going on
   depending on what dynamic prefix we use.
 * But that would be really great to define our own prefix or to be able to filter
   the prefix before the file gets uploaded.
 * For a very particular project, I need to reproduce a folder architecture on Amazon
   S3. Medias will go in folders using the “Real Media Libraries” and folders structure
   should be replicated on S3.
 * Do you think of any easy way to make this work without touching to the plugin’s
   core file ?
 * Thank you !

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [interfacelab](https://wordpress.org/support/users/interfacelab/)
 * (@interfacelab)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/custom-dynamic-prefix/#post-10935105)
 * Real Media Libraries doesn’t use a folder structure I thought, it’s strictly 
   a database thing?
 *  Thread Starter [christophekonig](https://wordpress.org/support/users/christophekonig/)
 * (@christophekonig)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/custom-dynamic-prefix/#post-10935337)
 * Yes you are right, it is just tagging, it doesn’t alter the files path physically
   but I need to reproduce the folder structure on S3 though.
 * That’s because editors will then browse into the S3 bucket, from other sites 
   to search for photos so files have to be separated in folders for simpler search.
 * The only problem with this is if the file is “moved” (not phisically) to another
   RML folder, the file will have to be moved on S3 too and I guess this is not 
   something your plugin is supposed to do, I was planning on developing that part
   myself.
 *  Plugin Author [interfacelab](https://wordpress.org/support/users/interfacelab/)
 * (@interfacelab)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/custom-dynamic-prefix/#post-10935354)
 * Well you can actually hook into this AFTER media cloud does and change everything:
 *     ```
       add_filter('wp_handle_upload_prefilter', function($file){
           add_filter('upload_dir', 'customUploadDir', 1001);
           return $file;
       }, 1001);
   
       add_filter('wp_handle_upload', function($fileinfo){
           remove_filter('upload_dir', 'customUploadDir');
           return $fileinfo;
       });
   
       function customUploadDir($params) {
           $newPath = '/whatever/you/like/here/';
           $params['path'] = str_replace($params['subdir'], $newPath, $params['path']);
           $params['url'] = str_replace($params['subdir'], $newPath, $params['url']);
           $parms['subdir'] = $newPath;
           return $params;
       }
       ```
   
 * Media Cloud will use whatever you specify in your function.
 *  Thread Starter [christophekonig](https://wordpress.org/support/users/christophekonig/)
 * (@christophekonig)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/custom-dynamic-prefix/#post-10935410)
 * Mmm I already tried hooking into “upload_dir” but that didn’t do the job and 
   in the debug log i have something like this :
 * 11/30/2018 7:28 pm ilab-media-tool INFO Finished uploading whatever/you/like/
   here//birthday-2.jpg to S3.
    11/30/2018 7:28 pm ilab-media-tool INFO End Upload
   file = 2018/11/birthday-2.jpg, time = 0.279597997665 11/30/2018 7:28 pm ilab-
   media-tool INFO Start Upload file = 2018/11/birthday-2.jpg 11/30/2018 7:28 pm
   ilab-media-tool INFO Uploading whatever/you/like/here//birthday-2.jpg to S3.
 * The code you provided also give the same result.
 *  Plugin Author [interfacelab](https://wordpress.org/support/users/interfacelab/)
 * (@interfacelab)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/custom-dynamic-prefix/#post-10935538)
 * I just pushed 2.1.21 which will honor whatever you return from `upload_dir`, 
   but in order for it to do so, you have to do one of the following:
 * – Make sure the Upload File Prefix setting is blank
    – Or, add a filter for the`
   ilab_storage_should_use_custom_prefix` hook and return `false`
 *     ```
       add_filter('ilab_storage_should_use_custom_prefix', function($should){
           return false;
       });
       ```
   
 *  Thread Starter [christophekonig](https://wordpress.org/support/users/christophekonig/)
 * (@christophekonig)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/custom-dynamic-prefix/#post-10935744)
 * Wow, it’s working great now !
 * And I’ve managed to move the file on S3 and update metadata whenever the file
   is moved inside another RML folder.
 * So, all is good, thank a lot for your help and for this great plugin.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Custom dynamic prefix’ is closed to new replies.

 * ![](https://ps.w.org/ilab-media-tools/assets/icon.svg?rev=2795439)
 * [Media Cloud for Bunny CDN, Amazon S3, Cloudflare R2, Google Cloud Storage, DigitalOcean and more](https://wordpress.org/plugins/ilab-media-tools/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ilab-media-tools/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ilab-media-tools/)
 * [Active Topics](https://wordpress.org/support/plugin/ilab-media-tools/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ilab-media-tools/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ilab-media-tools/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [christophekonig](https://wordpress.org/support/users/christophekonig/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/custom-dynamic-prefix/#post-10935744)
 * Status: resolved