Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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' );
share|improve this answer
    
Take a look at the wp-config.php and the constants there. This shouldn't get changed inside a plugin... –  kaiser Feb 1 '13 at 10:16
    
@kaiser They're not being changed, we're just using ABSPATH to get the WordPress root directory –  bungeshea_ Feb 1 '13 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 '13 at 10:36
    
@kaiser Good point. I guess I was referring to a one-time change; I'll update my answer –  bungeshea_ Feb 1 '13 at 10:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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