Custom location for attached images

Question

I managed to upload images out of where blog (WordPress) is installed, and I’m wondering to see how can I update default attached image path.

Few facts:

  • The main website is installed on docker. main.com
  • There is another stand alone WordPress website (blog) installed on docker: main.com/blog
  • There is a subdomain on separate docker where I keep blog/wp-content: media.main.com
  • UPLOAD directory for blog is out of wp-content directory and I can SSH to it by going to where the subdomain docker is: Docker/doc/media.main.com/blog/files
  • wp-content for blog is renamed to data
  • 755 for directories and 644 are set for files
  • Both dockers are in same IP
  • Both websites have their own database, nginx, php hosted on separate dockers

wp-config.php for blog website has following:

/** upload directory to be outside wp-content */
define( 'UPLOADS', '/media/blog/files' ); // where docker is mounted

/** new name for wp-content */
define( 'WP_CONTENT_DIR', '/media/blog/data' ); // where docker is mounted
define( 'WP_CONTENT_URL', 'https://media.main.com/blog/data' );

I already added the following code to blog functions.php

if (defined('UPLOADS')) {
    if (is_dir(UPLOADS)) {
        function files_dir($upload_dir){ 

            $upload_dir['path']    = str_replace( $upload_dir['basedir'], UPLOADS, $upload_dir['path'] );
            $upload_dir['basedir'] = UPLOADS;
            return $upload_dir;
        }
        add_filter('upload_dir', 'files_dir');
        } else {
        error_log('UPLOADS is defined but does not exist: ' . UPLOADS);
    }
}

In summary: I just not sure how can I have https://media.main.com/blog/files/image.jpg as attached image path in blog edit media page rather than: https://main.com/blog//media/blog/files/image.jpg (there is no typo here // is what I get)

ps.0: https://media.main.com/blog/files/image.jpg is accessible if I manually type it into address bar, but it is not the URL WordPress (blog) thinks images are, so I end up to have broken images on WordPress unless I manually update them

**Picture_1**: what I see in edit media page as attached image path

**Picture_2**: What I see in edit media page as attached image

0
, , , Nik 2 years 2019-11-26T18:37:10-05:00 0 Answers 71 views 0

Leave an answer

Browse
Browse