Home › Forums › Backend Issues (wp-admin) › 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
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.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re hard at work on ACF 6.1, and Beta 1 is now available 🚀
— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.