最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Problems with defining UPLOADS constant

programmeradmin1浏览0评论

I have a custom Wordpress file-structure like

web-root:

  • content (folder)

    • uploads (folder)
    • plugins (folder)
    • themes (folder) ... and so on
  • wordpress (folder)

    • wp-admin (folder)
    • wp-includes (folder) ... more folders
    • wp-blog-header.php
    • wp-load.php
    • wp-login.php ... and all other wp core files

.htaccess

index.php

wp-config.php

In my wp-config.php I have to define the path to my custom uploads folder like this:

if (!defined('UPLOADS')) {
    define('UPLOADS', '../content/uploads');
}

More or less out of nothing (maybe I updated the wp core) when trying to upload an image I get the error message saying: can't create folder check if parent folder is writeable.

BUT: if I put the same code into the wp-blog-header.php file uploading and building new folders within the upload folder works.

I thought using DEFINE(in my case) means that I just save a string value to a constant and where ever I use the constant the value is the same. But how can it be that there is a difference when defining a constant in wp-config.php or wp-blog-header.php? (which is inside the subfolder wordpress .

For my changes in wp-blog-header.php would disappear after the next Wordpress update I obviously can't solve it that way.

Any ideas what the problem could be?

I have a custom Wordpress file-structure like

web-root:

  • content (folder)

    • uploads (folder)
    • plugins (folder)
    • themes (folder) ... and so on
  • wordpress (folder)

    • wp-admin (folder)
    • wp-includes (folder) ... more folders
    • wp-blog-header.php
    • wp-load.php
    • wp-login.php ... and all other wp core files

.htaccess

index.php

wp-config.php

In my wp-config.php I have to define the path to my custom uploads folder like this:

if (!defined('UPLOADS')) {
    define('UPLOADS', '../content/uploads');
}

More or less out of nothing (maybe I updated the wp core) when trying to upload an image I get the error message saying: can't create folder check if parent folder is writeable.

BUT: if I put the same code into the wp-blog-header.php file uploading and building new folders within the upload folder works.

I thought using DEFINE(in my case) means that I just save a string value to a constant and where ever I use the constant the value is the same. But how can it be that there is a difference when defining a constant in wp-config.php or wp-blog-header.php? (which is inside the subfolder wordpress .

For my changes in wp-blog-header.php would disappear after the next Wordpress update I obviously can't solve it that way.

Any ideas what the problem could be?

Share Improve this question edited Nov 7, 2019 at 10:51 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Nov 7, 2019 at 10:36 LuckyfellaLuckyfella 5343 silver badges12 bronze badges 6
  • Can you try an absolute path instead of the relative one? – kero Commented Nov 7, 2019 at 10:44
  • Shouldn't it just be 'content/uploads' ? Since wp-config.php is within the root. – Bas van Dijk Commented Nov 7, 2019 at 10:57
  • @kero the path has to be relative because wordpress puts abspath before that – Luckyfella Commented Nov 7, 2019 at 11:01
  • @BasvanDijk because wordpress works inside the subfolder the abspath points to the subfolder and this way you have to go up one folder-level first – Luckyfella Commented Nov 7, 2019 at 11:03
  • 3 @Luckyfella Since plugins and themes are in there as well, can't you just set WP_CONTENT_DIR? – kero Commented Nov 7, 2019 at 11:05
 |  Show 1 more comment

1 Answer 1

Reset to default 0

(Converting my comment to an answer.)

Since you store themes and plugins in that folder as well, try setting the WP_CONTENT_DIR constant instead. (Always prefer absolute paths when possible.)

As to your specific case, why it worked in one file but not in another - this will probably involve more debugging, checking where exactly WP uses which constant, etc. If setting WP_CONTENT_DIR solves your problem, remove UPLOADS and work with it.

发布评论

评论列表(0)

  1. 暂无评论