Support

Account

Home Forums Backend Issues (wp-admin) Change file upload path to WP Root?

Solving

Change file upload path to WP Root?

  • I’m stuck, I’m currently trying to modify the path to place uploads in the root directory so that downloads can be accessed by example.com/document.pdf

    https://support.advancedcustomfields.com/forums/topic/change-file-upload-path-for-one-specific-field/

    Does anyone know how to modify this to achieve the results? I’ve played around with the path settings and base URL and can’t get it to work.

    Thanks!
    Austin

  • Had this exact issue, wrote a blog post about it here: https://www.ractoon.com/2016/08/wordpress-acf-pro-files-field-custom-upload-directory/

    But your code would end up looking something like:

    
    add_filter( 'acf/upload_prefilter/name=secure_files', 'secure_upload_prefilter' );
    add_filter( 'acf/prepare_field/name=secure_files', 'secure_files_field_display' );
    
    public function secure_upload_prefilter( $errors ) {
    
      add_filter( 'upload_dir', 'secure_upload_directory' );
    
      return $errors;
    
    }
    
    function secure_upload_directory( $param ) {
            
      $folder = '/s2member-files';
    
      $param['path'] = WP_PLUGIN_DIR . $folder;
      $param['url'] = WP_PLUGIN_URL . $folder;
      $param['subdir'] = $folder;
      $param['basedir'] = WP_PLUGIN_DIR;
      $param['baseurl'] = WP_PLUGIN_URL;
    
      return $param;
    
    }
    
    public function secure_files_field_display( $field ) {
    
      // update paths accordingly before displaying link to file
      add_filter( 'upload_dir', 'secure_upload_directory' );
    
      return $field;
    
    }
    

    Where the secure_files portion of the add_filter would be your field name instead.

    Then in the secure_upload_directory() function you could use https://codex.wordpress.org/Function_Reference/get_home_path to grab the absolute path to the install location.

  • Hi Ractoon,

    Thank you for the article, I followed it. I am able to upload images through an acf field but it uploads it twice one in folder name in plugins folder and another in uploads folder. i dont mind it to be uploaded in plugins or uploads but I do not want the images to be seen in the Media in Admin section. The issue is it shows the broken image icon in Media folder and broken image icon on acf filed as well. How can I skip the uploading to Media folder.

    The field is in repeater on a custom post type.

    Please help

    Thank You.

  • Hi @develop,

    If images are showing up blank it sounds like there might be an error in the path to the uploaded file. You can check this by going to the Media section in the WordPress admin, clicking on the image and checking it’s URL field.

    For hiding images in the media folder you’ll probably need to do something like: http://wordpress.stackexchange.com/a/105465/12291

  • Hi,

    I checked the link in Media and checked the image in post type, it uploads the same image in uploads folder as well as plugins folder.

    The ACF field I am using is repeater field for custom post type. It correctly uploads in pluguns folder buy it should skip uploads so then it won’t be seen in Media in the admin

    Thank you.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Change file upload path to WP Root?’ is closed to new replies.