0

both main and second domain (addon domain ) are in same host i want to find a way to change upload directory to another directory that located in another domain root.

default location (first location) : My main domain upload directory is : /domains/domain1.com/public_html/wp-content/uploads

destination location (second location) : the destination directory. is : /domains/domain2.com/public_html/wp-content/uploads

I want to define second domain upload directory as main domain upload dir

I mean I want domain1.com upload directory uses from the second domain upload directory.

for example can i use another wordpress root location address from same host in this code in wp-config.php ?

 wp config function: define('UPLOADS', 'destination directory');

if its matter i use shared hosting and my control panel is directadmin

is this possible ?

4

2 Answers 2

1

Well, what you want to achieve saving uploads in another domain? You want to share the uploads folder with another domain?

Did you know you can use more than one domain (site) in a single WordPress Installation? It's called Multisite: https://premium.wpmudev.org/blog/ultimate-guide-multisite/

To change the upload dir. Just use the filter upload_dir. It's documented here:

https://codex.wordpress.org/Plugin_API/Filter_Reference/upload_dir

Be happy!

11
  • Exactly i want to share just upload folder between two websites for edd products. but in multisite there is some limit for manage, thank you a lot for your help i will test this , Jun 19, 2019 at 13:30
  • can you help me how can i set this location as default location : /home2/username/domains/domain2.com/public_html/wp-content/uploads - I don't know how to use this filter. - if you can't its ok i try to find a way to use this and And I'm very grateful to you for your time. Jun 19, 2019 at 14:00
  • First of all, changing uploads folder will only change where wordpress will save your uploads. How you would get the uploads in media library of wordpress to attach in some of your products? I think you could think in a solution to share the media of the sites. Like if i upload a media in my site, will appear in other site too, like a sync feature. Let's look if have some plugin to solve your problem. Jun 19, 2019 at 14:21
  • Yes, What I want is have access the files that I upload on one of the sites from another site too in media library, exactly as you said. Jun 19, 2019 at 14:40
  • There is no php function to load another root of same host ? For example :$_SERVER['DOCUMENT_ROOT'] will be load current files directory , if in this : define('UPLOADS', 'destination directory'); we can put another domains files location (/domains/domain2.com/public_html/wp-content/uploads) - so the problem will be sloved but it seems there is no way for this . Is there a way to do this? Jun 19, 2019 at 14:51
0

Yes, it's possible with Linux symlinks! We do this now on SlickStack staging sites.

There is no way to do it using WordPress configuration settings alone -- WordPress is rather finicky with the /uploads/ folder in particular, because the defined path must be relative to /wp-content/ so hacking settings will not work, unless you want to share the entire directory tree which is usually not what questions like yours are looking for.

But you can easily "trick" WordPress into sharing a single folder with symlinks.

In your case, point symlink like this:

sudo ln -s -f /domains/domain1.com/public_html/wp-content/uploads /domains/domain2.com/public_html/wp-content/uploads

Remember, for symlinks the first directory is "canonical" or the physical source, and the second directory is the actual symlink (virtual directory).

You might also want to setup a cron job to ensure the symlink doesn't get overwritten.

2
  • @TomJNowell Why are you censoring my posts? Self-promotion is verbosely allowed in the rules when relevant and helpful as a coding example. Please stop stalking me all over WPSE, thanks. wordpress.stackexchange.com/help/promotion Jul 28 at 22:53
  • You did not disclose your affiliation, nor did it help the answer or explain how it helped, and reposted it on multiple questions. If you find duplicates you should vote to close them as duplicates rather than reposting answers, or flag them if you haven't earnt enough rep to do that yet. As for why I'm looking into it, I'm a community moderator here. If you want to discuss or dispute the links, ask for advice, or ask if your specific case should be allowed then you should post on the meta stack, that's where discussion about the site itself should go.
    – Tom J Nowell
    Jul 28 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.