How to save media files under “http://example.com/custom_folder” for a specific page

Try this

add_filter('upload_dir', 'upload_image_specific_calback');
function upload_image_specific_calback( $param ){

    //$_GET['post'] which is your target post like 10 is post id.
    //After click update button.
    if(isset($_GET['post'])){
        if($_GET['post'] == 10){
            $param = array(
            'path' => get_home_path().'logos',
            'url' => home_url().'/logos',
            'subdir' => '',
            'basedir' => get_home_path(),
            'baseurl' => home_url(),
            'error' => false
            ); 
        }
    }

    //$_POST['post_id'] which is your target post like 10 is post id.
    //instant upload time before save
    if(isset($_POST['post_id'])){ 
        if($_POST['post_id'] == 10) {
            $param = array(
            'path' => get_home_path().'logos',
            'url' => home_url().'/logos',
            'subdir' => '',
            'basedir' => get_home_path(),
            'baseurl' => home_url(),
            'error' => false
            );
        }   
    }

    error_log("path={$param['path']}");  
    error_log("url={$param['url']}");
    error_log("subdir={$param['subdir']}");
    error_log("basedir={$param['basedir']}");
    error_log("baseurl={$param['baseurl']}");
    error_log("error={$param['error']}"); 
    return $param;
}

Leave a Comment