2

I am trying to define the wordpress upload folder outside the installation directory. My directory structure is:

/path/to/my/base/folder 
               |-> wordpress (the wordpress installation)
               |-> uploads (the required upload folder)

I have tried defining the 'UPLOADS' in my wp-config.php like:

define('UPLOADS', '../uploads');

Wordpress creates the folder and the images are uploaded there, but cannot use it when required. The image URL looks like :

www.myhost.dev/../uploads/image-file-name-format.jpg

But if I use absolute path to define the 'UPLOADS' like

define('UPLOADS', '/path/to/my/base/folder/uploads');

this works.

But the problem is, then the image url looks something like:

www.myhost.dev//path/to/my/base/folder/uploads/image-file-name-format.jpg

This tells the location of the file and this can be a security issue.

So, is there a better way to define the relative path for the uploads folder which will point to my required folder?

Thanks in advance.

2
  • I'm unsure if you could do this, even if you could get it to work -- The images loaded into that directory wouldn't be accessible via any public path, correct? Unless you did some funky path rerouting in server configs. Do you need the images to be viewable after uploading, or are you just doing a document "bucket" of some sort? Jun 30, 2016 at 17:15
  • @GregBurkett I am trying to have the normal uploads folder and not trying to have just a document bucket. I am trying to do some symlink-ing now. If I find any, I will surely post it here.
    – Stiff Roy
    Jul 1, 2016 at 10:03

3 Answers 3

2

A couple of notes that may help people:

define( 'UPLOADS' , 'blah') is typically RELATIVE to the WordPress core root directory. The default is 'wp-content/uploads'. If you try to put the uploads outside of the WordPress directory with something like '../uploads/' as the define the upload URL will typically not work causing problems.

If you set the path with the define() inside your wp-config.php WordPress will NOT read the upload_path setting, if you have used it.

I found that setting the upload_path option in WordPress is better for storing media files outside the WordPress install path. Login to your WP Admin and go to the url /wp-admin/options.php to see the "raw" options list for WordPress.

Look for the upload_path setting. Put in your FULL PATH on the server like /usr/wpsite/uploads/ where /usr/wpsite/public_html would be where your WordPress core install typically ends up. Save the settings.

Your uploads will now be placed OUTSIDE the WordPress install directory. Make sure the web server has read/write permissions to the directory.

Also note that WordPress will put ALL FILES in that directory. It will not separate them into year/month subfolders as is the default for a typical WordPress install. If someone knows how to retain that feature please comment.

1

I have done it at last by making a symlink with proper permissions. In my case, when I tried to make a symlink, the symlink did not have enough permission to write into the folder. This was because of my system (I am using Macbook). So what I did is:

$ cd wp-content
$ mv uploads /path/to/my/base/folder/
$ ln -s ../../uploads uploads
$ chmod -h 777 uploads

Check the last line where I have changed the permission for the symlink. Normally in most of the cases, you don't need to change the permission of the symlink, as they inherit the permission of the folder.

0

If you take a look at this link http://www.wpbeginner.com/wp-tutorials/how-to-change-the-default-media-upload-location-in-wordpress-3-5/

You need to use a path like so

define( 'UPLOADS', ''.'uploads' );

2
  • 1
    This looks like it would work, but the OP mentions needing the upload folder to be actually one folder HIGHER than wp-content, not in the same folder. That seems to be the tricky bit Jun 30, 2016 at 17:22
  • @Alastair this is not so simple as you are thinking. I know this settings of wordpress but please read my description. I have described my situation very well.
    – Stiff Roy
    Jul 1, 2016 at 10:01

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.