WordPress.org

Support

Support » How-To and Troubleshooting » Change upload location using 'upload_dir' filter

Change upload location using 'upload_dir' filter

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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');

    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?

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

    Thanks Duck_Boy

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Change upload location using 'upload_dir' filter’ is closed to new replies.
Skip to toolbar