Opened 30 hours ago
Last modified 21 hours ago
#49658 new defect (bug)
Incorrect Upload Directory path using wp_upload_dir()
Reported by: | amitkumarsingh | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.3.2 |
Component: | Upload | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description (last modified by )
I usually don't use windows when coding with WordPress.
I was creating a file in the uploads directory and decided to use wp_upload_dir() to get the upload directory path. When I printed the result, I noticed that the path returned was incorrect.
Below is the print_r result of the wp_upload_dir() function:
Array ( [path] => C:\xampp\htdocs\test/wp-content/uploads/2020/03 [url] => http://localhost/jan/wp-content/uploads/2020/03 [subdir] => /2020/03 [basedir] => C:\xampp\htdocs\test/wp-content/uploads [baseurl] => http://localhost/jan/wp-content/uploads [error] => )
As soon as the path enters in the WordPress directory, backslashes are converted to front slashes.
Change History (3)
#2
@
28 hours ago
Thanks for the reply.
While I see what you say about the forward and backward slashes to be true when accessing through file explorer, I still get a 500 Internal Server error when using the PATH retrieved by wp_upload_dir() function.
Whereas there are no issues when I use wp_upload_dir() on Linux.
Trac #44654 does make a good point that DIRECTORY_SEPARATOR should be used.
But, the point here to note is the path is being returned by the function and not by plugin code.
#3
@
21 hours ago
- Component changed from General to Upload
- Description modified (diff)
- Keywords reporter-feedback added; needs-patch removed
Hi there, welcome back to WordPress Trac! Thanks for the ticket.
Using DIRECTORY_SEPARATOR
in core has been discussed several times before, most recently in #28811, #29726, and #44654. Since Windows recognizes both types of slashes, there is no strong reason for changing this if everything works as expected.
Anywhere in core or plugins where paths need to be compared, wp_normalize_path()
should be used.
Some more previous discussions: #15598, #16457, #17494, #20849.
I still get a 500 Internal Server error when using the PATH retrieved by wp_upload_dir() function.
Could you provide the steps to reproduce the issue on a clean install? How are you using the path?
I don't think this is actually a problem - both forward slashes and backslashes can be used as directory separators on Windows. See also #44654.