I have developed a plugin and in my plugin there is a custom media uploader. When i upload any file from my plugin uploader that file is uploaded and saved in WordPress default uploads/
folder.
But I want that when i upload file from my plugin uploader those files should be uploaded in a new folder inside WordPress custom uploads
folder so I search from google and found this code:
<?php
function upload_dir($dirs)
{
$dirs['subdir'] = '/my-uploads';
$dirs['path'] = $dirs['basedir'] . '/my-uploads';
$dirs['url'] = $dirs['baseurl'] . '/my-uploads';
return $dirs;
}
add_filter('upload_dir', 'upload_dir');
?>
Now all files that are uploaded from (posts, pages etc) are also stored in that plugin folder.
I want that only those files which are uploaded from my plugin uploader should be saved in that my-folder
, and rest of the files should be saved in WordPress default uploads
folder…
Right before the uploading code, use
Then after your uploading code, use:
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:
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?
Here is a working solution.