How to change upload directory in my plugin uploader How to change upload directory in my plugin uploader wordpress wordpress

How to change upload directory in my plugin uploader


Right before the uploading code, use

add_filter('upload_dir', 'upload_dir'); 

Then after your uploading code, use:

remove_filter('upload_dir', 'upload_dir'); 

That way, the filter only works for your plugin uploads and not on other places.


You might need to handle the file processing yourself using plain PHP. When you process the form, try this:

$uploaddir = '/path/to/plugin/uploads/';$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);if( move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))    echo 'success!';else    echo 'fail!';

and use print_r($_FILES); to debug.

Be very, very careful though - you're potentially creating a security risk. see Secure PHP File Upload Script for more info on that.


It could have to do with the .htaccess settings. The .htaccess file creates limits as to what you can do. Or it could be some other setting outside of your file. Have you tried running this on more than 1 server to test it out?