Title: Using the &#8220;UPLOAD_DIR&#8221; filter
Last modified: April 6, 2018

---

# Using the “UPLOAD_DIR” filter

 *  Resolved [greg](https://wordpress.org/support/users/gllorca/)
 * (@gllorca)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/using-the-upload_dir-filter/)
 * Dear all,
 * I am using Nextgen gallery plugin on a multisite network.
 * One of my custom plug-ins uses this code :
 *     ```
       // Forcing all sub-domains to use the same uploads folder
       if( !function_exists( 'no_uploads_subfolders' ) ){
       	function no_uploads_subfolders( $dirs ) {
       		$dirs['baseurl'] = network_site_url( '/wp-content/uploads' );
       		$dirs['basedir'] = ABSPATH . 'wp-content/uploads';
       		$dirs['path'] = $dirs['basedir'] . $dirs['subdir'];
       		$dirs['url'] = $dirs['baseurl'] . $dirs['subdir'];
   
       		return $dirs;
       	}
       }
       add_filter( 'upload_dir', 'no_uploads_subfolders' );
       ```
   
 * However, when I upload an image in NextGen gallery, the resulting file is saved
   at /wp-content/uploads/site/2/nggallery instead of /wp-content/uploads/nggallery
   as I would like to.
 * Could you please help me force this plugin to use the root folder, as I share
   images and galleries accross multiple sites ?
 * Thank you very much !
 * By the way : I am using it on a staging website and therefore won’t have any 
   public URL to share, sorry.

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

 *  Plugin Contributor [Imagely](https://wordpress.org/support/users/imagely/)
 * (@imagely)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/using-the-upload_dir-filter/#post-10154474)
 * [@gllorca](https://wordpress.org/support/users/gllorca/) – This is all we can
   offer currently:
 *     ```
       add_filter('ngg_datamapper_table_name', 'something', 10, 2);
       function something( $table_name, $name ) {
         global $table_prefix;
         if ( strpos( $table_name, ‘ngg' ) !== FALSE ) {
           return $table_prefix . $name;
         }
       }
       ```
   
 * The callback function is noted as “something” use whatever is most appropriate
   for your installation.
 * The return value of `$table_prefix . $name` will return by default the main WordPress
   installation site, if you want to use a different sub-site then set the `$table_prefix`
   appropriately, for example, site 3 would use `wp_3_` as the `$table_prefix`
 * Also to note, all images should be uploaded to the specific site being used for
   all the other sub-sites.
 * Thanks!
 * – Cais.
 *  Thread Starter [greg](https://wordpress.org/support/users/gllorca/)
 * (@gllorca)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/using-the-upload_dir-filter/#post-10169678)
 * Dear Cais,
    Thank you for your help. I don’t really understand how this code 
   helps me solve the uploads folder issue.
 * The table prefix is fine.
 * The problem is the matter of the “specific site” sub-folder in the uploads/ directory.
   The plug-in is not supposed to use a “specific site” subfolder, it should upload
   pictures directly in wp-content/uploads/
 *  Plugin Contributor [Imagely](https://wordpress.org/support/users/imagely/)
 * (@imagely)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/using-the-upload_dir-filter/#post-10171328)
 * [@gllorca](https://wordpress.org/support/users/gllorca/) – Perhaps I am not understanding
   what you are looking for and/or you are wanting to use something other than the
   following default: `wp-content/uploads/sites/%BLOG_ID%/nggallery/` for your gallery
   paths?
 * – Cais.
 *  Thread Starter [greg](https://wordpress.org/support/users/gllorca/)
 * (@gllorca)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/using-the-upload_dir-filter/#post-10171435)
 * Dear Cais,
    Thank you for your answer. Yes, that is exactly that. I’d like to
   use wp-content/uploads/nggallery/ or directly wp-content/uploads/
 *  Plugin Contributor [Imagely](https://wordpress.org/support/users/imagely/)
 * (@imagely)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/using-the-upload_dir-filter/#post-10178854)
 * [@gllorca](https://wordpress.org/support/users/gllorca/) – Did you change the
   default appropriately (although under a multisite I would not expect or recommend
   not including the site ID as part of the upload path)?
 * Although, again, the code we suggested above is the best workaround we can suggest
   if you want to share all images across all sub-sites with NextGEN Gallery.
 * Thanks!
 * – Cais.

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

The topic ‘Using the “UPLOAD_DIR” filter’ is closed to new replies.

 * ![](https://ps.w.org/nextgen-gallery/assets/icon-256x256.png?rev=2083961)
 * [Photo Gallery, Sliders, Proofing and Themes - NextGEN Gallery](https://wordpress.org/plugins/nextgen-gallery/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nextgen-gallery/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nextgen-gallery/)
 * [Active Topics](https://wordpress.org/support/plugin/nextgen-gallery/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nextgen-gallery/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nextgen-gallery/reviews/)

## Tags

 * [upload_dir](https://wordpress.org/support/topic-tag/upload_dir/)

 * 5 replies
 * 2 participants
 * Last reply from: [Imagely](https://wordpress.org/support/users/imagely/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/using-the-upload_dir-filter/#post-10178854)
 * Status: resolved