MyBB Community Forums

Full Version: Upload paths inaccuracy
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Upload paths should support both forms, absolute and "relative" paths (if ./ is specified, you point the start of the path to MYBB_ROOT), as admin/modules/tools/system_health.php already does.

For example, on admin/modules/forum/attachments.php#L235, absolute paths would not be supported.

Or, the whole inc/functions_upload.php considers the admin directory one level up from MYBB_ROOT (what if I specify the admin directory two level ups?).

Not specifying MYBB_ROOT on upload paths (as function_upload does) could bring to unexpected behaviours (error due to the execution of tasks using cron, where $_SERVER['DOCUMENT_ROOT'] is not set):

<error>
    <dateline>1560304831</dateline>
    <script>inc/functions_upload.php</script>
    <line>160</line>
    <type>2</type>
    <friendly_type>Warning</friendly_type>
    <message>opendir(./uploads/avatars): failed to open dir: No such file or directory</message>
    <back_trace>#0  errorHandler->log_error(2, opendir(./uploads/avatars): failed to open dir: No such file or directory, inc/functions_upload.php, 160) called at [/***/inc/class_error.php:189]
#1  errorHandler->error(2, opendir(./uploads/avatars): failed to open dir: No such file or directory, inc/functions_upload.php
#2  opendir(./uploads/avatars) called at [/***/inc/functions_upload.php:160]
#3  remove_avatars(121577895) called at [/***/inc/datahandlers/user.php:1668]
#4  UserDataHandler->delete_content() called at [/***/inc/datahandlers/user.php:1536]
#5  UserDataHandler->delete_user(Array ([121577414] =>
Added more informations on the last error now that I had the time to debug it. What I would suggest for that problem:

creating a function to call everytime that an upload path is called, something like:

function get_upload_path($path)
{
 return my_substr($path, 0, 1) === "." ? MYBB_ROOT.$path : $path;
}

or initialize in the init.php with the other settings initializations (if this pattern is still accepted) the correct path to upload path and avatar upload path (with the approach of the function).

Both solutions would also avoid all the checks defined('IN_ADMIN') to make it compatible with admin cp features.
Geel free to open a PR
(2019-06-15, 04:43 PM)Eldenroot Wrote: [ -> ]Geel free to open a PR


Geel?

Suddenly, I geel good!
(2019-06-15, 04:43 PM)Eldenroot Wrote: [ -> ]Geel free to open a PR
should not I wait my men to approve it?
Hi,

Thank you for your report. We have pushed this issue to our Github repository for further analysis where you can track our commits and progress with fixing this bug. Discussions regarding this bug may also take place there too.

Follow this link to visit the issue on Github: https://github.com/mybb/mybb/issues/3754

Thanks for contributing to MyBB!

Regards,
The MyBB Group