#48506 closed defect (bug) (duplicate)
wp_mkdir_p does not support relative paths
Reported by: | greengremlin | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.2.4 |
Component: | Filesystem API | Keywords: | |
Focuses: | Cc: |
Description
I have a wordpress install where the uploads folder is one level above the root path.
/www/public/wordpress
(WordPress root)
/www/public/uploads
(Uploads folder)
Here's the relevant wp-config.php
:
<?php if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/wordpress/'); define('WP_SITEURL', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/wordpress'); define('UPLOADS', '../uploads');
This works well and I've had no issues until recently. I just traced a bug in the FooGallery plugin where thumbnails were not getting generated to the fact that it was calling wp_mkdir_p
with a path that includes ..
, which resulted in the directory not getting created.
It seems wp_mkdir_p
needs to resolve the relative path, before trying to create the folder.
For example:
<?php wp_mkdir_p('/www/public/wordpress/../uploads/cache/2019/07/2019-my-pic');
Should resolve the path to /www/public/uploads/cache/2019/07/2019-my-pic
and create the folder using the resolved path.
Change History (3)
This ticket was mentioned in Slack in #core by mpcube. View the logs.
5 years ago
#2
@
5 years ago
#3
@
5 years ago
- Component changed from General to Filesystem API
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
@greengremlin
Hello and welcome to trac!
This is being discussed in #48316 so I have closed this ticket as a duplicate to allow discussion to remain in one place. You can watch or comment on the original ticket to be notified by email of updates.
Thanks,
Pete
I dont' know, what exactly the reason for this change was, but for me the following solution would fit:
In _wp_upload_dir(): use path_join() to join ABSPATH and UPLOADS (not just ABSPATH and $upload_path)
In path_join(): replace /foo/bar/../baz with /foo/baz so that UPLOADS and $upload_path can be a string starting with ../