当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Upload folder of Wordpress outside the project

问题描述:

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.

网友答案:

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' );

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: