0

I am using one plugin to upload all the client files. By default all the uploading files stored in the path wp-content/uploads/-plugin-name- . How to store all my files in my custom directory that somewhere in root of wordpress.

1 Answer 1

2

The upload directory and URL paths are stored in the options database. You can change them using update_option():

update_option( 'upload_path', ABSPATH . '/path/to/uploads' );
update_option( 'upload_path_url', site_url( '/uploads/' ) );

However, it's best not to use this in a publiuc plugin, as it will cause numerous issues. We can instead hook into the filters that control the result of getting these options and set them to our custom paths:

function wpse_84046_upload_path( $path ) {
    return '/path/to/uploads';
}
add_filter( 'pre_option_upload_path', 'wpse_84046_upload_path' );

function wpse_84046_upload_path_url( $url ) {
    return site_url( '/uploads/' );
}
add_filter( 'pre_option_upload_path_url', 'wpse_84046_upload_path_url' );
4
  • Take a look at the wp-config.php and the constants there. This shouldn't get changed inside a plugin...
    – kaiser
    Feb 1, 2013 at 10:16
  • @kaiser They're not being changed, we're just using ABSPATH to get the WordPress root directory
    – shea
    Feb 1, 2013 at 10:22
  • Assuming that you're using wp_upload_dir() and such, you should use this during calling it, not setting. Use 'pre_option_upload_path' to set a path relative to the ABSPATH. When you're changing this from a plugin you'll anyway have dozens of problems. Especially when already got files in the original directory.
    – kaiser
    Feb 1, 2013 at 10:36
  • @kaiser Good point. I guess I was referring to a one-time change; I'll update my answer
    – shea
    Feb 1, 2013 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.