[wp-trac] [WordPress Trac] #49658: Incorrect Upload Directory path using wp_upload_dir()

WordPress Trac noreply at wordpress.org
Tue Mar 17 20:15:48 UTC 2020


#49658: Incorrect Upload Directory path using wp_upload_dir()
-------------------------------+------------------------------
 Reporter:  amitkumarsingh     |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Upload             |     Version:  5.3.2
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------
Changes (by SergeyBiryukov):

 * keywords:  needs-patch => reporter-feedback
 * component:  General => Upload


Old description:

> 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.

New description:

 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.

--

Comment:

 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?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49658#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list