jeudi 2 juin 2016

How to change upload directory in my plugin uploader

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...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire