WordPress.org

Ready to get started?Download WordPress

Forums

Change upload location using 'upload_dir' filter (5 posts)

  1. David Gard
    Member
    Posted 2 years ago #

    Hey all,

    Does anybody know how to use the 'upload_dir' filter successfully?

    I'm trying to change the location via a filter if the user is on a specific page but I am failing, so any help is much apprciated.

    The filter is working as when I call <?php echo '<pre>'; print_r(wp_upload_dir()); echo '</pre>'; ?> I see the desired file paths, but it doesn't seem to be getting called when I actually upload an image.

    function djg_upload_folder(){
    	$array = array(
    		'path' => WP_CONTENT_DIR.'/uploads/custom-admin-images',
    		'url' => WP_CONTENT_URL.'/uploads/custom-admin-images',
    		'subdir' => '',
    		'basedir' => WP_CONTENT_DIR.'/uploads',
    		'baseurl' => WP_CONTENT_URL.'/uploads',
    		'error' => false
    	);
    	return $array;
    }

    Thanks.

  2. santosh.sahoo
    Member
    Posted 2 years ago #

    Try this way.

    function resume_photo_upload_dir( $pathdata ) {
         // change path here
         return $pathdata;
    }
    
    add_filter('upload_dir', 'resume_photo_upload_dir');
    
    $time = current_time('mysql');
    
    $overrides = array('test_form'=>false);
    
    $file = wp_handle_upload($_FILES['your-photo'], $overrides, $time);
    
    remove_filter('upload_dir', 'resume_photo_upload_dir');
  3. Jason
    Member
    Posted 2 years ago #

    Ok, so is it possible to move the uploads folder to another server all together? And externally access the files via subdomain?

    Like upload all files to media.whatever.com?

  4. David Gard
    Member
    Posted 2 years ago #

    You'd be better off starting a new thread, as most people look for threads with no replys.

  5. Jason
    Member
    Posted 2 years ago #

    Thanks Duck_Boy

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.