Opened 5 years ago
Last modified 4 years ago
#5953 reopened defect (bug)
Absolute upload_path fails
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Upload | Version: | |
| Severity: | normal | Keywords: | |
| Cc: |
Description
- On Options/Misc, enter "/tmp/foo/bar" as a value for the upload path setting.
- Write a new post and attach an image.
Expected: the image file should be stored as /tmp/foo/bar/2008/02/file.jpg or similar.
Actual: a 'tmp/foo/bar' subdirectory is created within ABSPATH (if that's possible) and the file is stored there. Both the filesystem path and URL path just append '/tmp/foo/bar', so you get 'ABSPATHtmp/foo/bar/2008/02/file.jpg' and 'http://example.com//tmp/foo/bar/2008/02/file.jpg'
An absolute upload_path should probably be rejected unless you also specify an upload_url_path, because there's no way to know what URL corresponds to an arbitrary filesystem path.
Attachments (1)
Change History (18)
comment:1
tellyworth
— 5 years ago
tellyworth
— 5 years ago
comment:2
tellyworth
— 5 years ago
The attached patch fixes the main issue. It doesn't do anything about the case where upload_path is absolute and upload_url_path is empty - that probably needs a second opinion.
path_is_absolute() and path_join() might be useful elsewhere.
I also snuck in a minor addition: wp_upload_dir() now returns an extra element that just contains the subdir within the upload directory (if any). That might be useful for fixing the file attachment guid situation.
comment:3
tellyworth
— 5 years ago
Unit tests are here:
http://svn.automattic.com/wordpress-tests/wp-testcase/test_uploads.php
test_upload_dir_absolute() covers the bug.
comment:4
nbachiyski
— 5 years ago
In path_join() you can use DIRECTORY_SEPARATOR instead of /.
comment:6
ryan
— 5 years ago
- Owner changed from anonymous to tellyworth
Leaving open in case we want to use DIRECTORY_SEPARATOR.
comment:7
tellyworth
— 5 years ago
Initially I wrote that function with DIRECTORY_SEPARATOR, but that constant isn't used anywhere else in WP so I changed it for consistency. Also, using / instead of DIRECTORY_SEPARATOR leaves open the possibility of using path_join() on URL paths.
We could use the constant and perhaps create a second function, url_path_join(), that always uses a /. But I think for that to make sense we'd need to review and change all paths in WP to use DS instead of a hard coded slash.
comment:8
nbachiyski
— 5 years ago
- Resolution set to fixed
- Status changed from new to closed
Actually I agree. / works as a separator in Windows and writing path_join or DIRECTORY_SEPERATOR all the time is very tiresome.
comment:9
Otto42
— 5 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
path_join doesn't appear to work properly for some people.
Reference this support thread:
http://wordpress.org/support/topic/182297
comment:10
DD32
— 5 years ago
path_join doesn't appear to work properly for some people.
Looking at the code, That'd probably be caused by path_is_absolute() => realpath(), I cant see how the regular expressions could be missing it.
comment:11
santosj
— 5 years ago
- Milestone changed from 2.5 to 2.9
comment:12
Denis-de-Bernardy
— 4 years ago
- Component changed from General to Upload
comment:13
Denis-de-Bernardy
— 4 years ago
realpath() is buggy on some servers. we could try to use the shell:
echo $PWD
but that wouldn't make much of a difference -- if realpath() fails, exec() probably does as well.
comment:14
nbachiyski
— 4 years ago
$PWD is different than realpath('.'). realpath resolves symlinks and relative references (. and ..). Historically it had caused a lot of problems in the UNIX world, because of strange/buggy implementations.
If realpath fails, we can use dirname to resolve at least . and .. and forget about the symlinks.
comment:15
Denis-de-Bernardy
— 4 years ago
True. For what it's worth, though, I've found this quite useful in various shell scripts:
path=`cd $PWD && pwd`
I've yet to see it fail on a symb links.
comment:16
Denis-de-Bernardy
— 4 years ago
see: #7640
comment:17
ryan
— 4 years ago
- Milestone changed from 2.9 to Future Release
Ah. There's another precondition required to reproduce: /tmp, /tmp/foo or /tmp/foo/bar is a symbolic link.