#10559 closed enhancement (invalid)
Allow a custom subdir in wp_upload_dir
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Upload | Keywords: | has-patch needs-testing |
| Focuses: | Cc: |
Description
Sometimes it's nice to keep a certain set of uploaded files separate from the rest. Especially if you're not allowing direct access to them. I usually do this by putting the files in a subdirectory of the uploads directory with a .htaccess rule to block access. I've been using a modified version of the wp_upload_dir which allows you to specify a sub-directory. For example, wp_upload_dir( null, 'premiums') would use a directory like wp-content/uploads/premiums/2009/08
Attachments (2)
Change History (9)
#3
follow-up:
↓ 5
@
16 years ago
Not all uploads have a post.
Also, the second patch was just to add the documentation. I meant to have it overwrite the first upload...oops.
#4
@
16 years ago
I'm sorry, I should be more specific. I'm using my custom wp_upload_dir function to upload files to the right place which aren't associated with any post. They are just for a plugin. For example, a plugin like blog icons by Joost could use this to put the icons in wp-content/uploads/blog-icons and my attachment manager plugin could upload the icons used for attachments to wp-content/uploads/attachment-manager. Those examples both assume that the blog is using the default wp-content/uploads, but if the blog has a different upload dir, that would be used (%%upload_dir%%/%%subdir%%/ or %%upload_dir%%/%%subdir%%/YYYY/MM/)
#5
in reply to:
↑ 3
@
16 years ago
Replying to aaroncampbell:
Not all uploads have a post.
Also, the second patch was just to add the documentation. I meant to have it overwrite the first upload...oops.
in this case, you don't need the patch at all.
add_filter('upload_dir', 'foobar');
$dir = upload_dir()l
remove_filter('upload_dir', 'foobar');
and have foobar() amend the dir as needed. what's desperately needed in that function is a post_id argument; not a subdir argument.
#6
@
16 years ago
- Resolution set to invalid
- Status changed from new to closed
Good point. I don't know why I missed the obvious. Here is what I did for anyone else ending up here with a similar issue:
add_filter('upload_dir', 'my_upload_dir');
$upload = wp_upload_dir();
remove_filter('upload_dir', 'my_upload_dir');
funcion my_upload_dir($upload) {
$upload['subdir'] = '/sub-dir-to-use' . $upload['subdir'];
$upload['path'] = $upload['basedir'] . $upload['subdir'];
$upload['url'] = $upload['baseurl'] . $upload['subdir'];
return $upload;
}
I'd be disagreeable on that one. passing the post_id to the upload_dir filter would be a *much* better implementation. it's then the plugin's job to determine if any subdir applies.