Upload after Media Library Folders has checked folders:
New folder created on the fly so not yet checked by Media Library Folders:
Even if I get this error, the file is correctly uploaded and if I close the Media Library popup and reopen it, I can select the file and attach it to the post.
To change the upload folder I use “upload_dir” hook the function is this one:
function change_upload_dir( $param ) {
$request = array_change_key_case( $_REQUEST, CASE_LOWER );
if ( isset($request['post_id']) )
$post_id = $request['post_id'];
else
$post_id = $request['post'];
$brand = get_post( get_field('relations', $post_id )['brand'][0] )->post_name;
$path = '/risorse/' . $brand;
$param['path'] = $param['basedir'] . $path;
$param['url'] = $param['baseurl'] . $path;
$param['subdir'] = $path;
return $param;
}
Is there away to force check folders with a hook in your plugin or something similar?
I hope I explained enough my problem…
Thank you
]]>I am using Nextgen gallery plugin on a multisite network.
One of my custom plug-ins uses this code :
// Forcing all sub-domains to use the same uploads folder
if( !function_exists( 'no_uploads_subfolders' ) ){
function no_uploads_subfolders( $dirs ) {
$dirs['baseurl'] = network_site_url( '/wp-content/uploads' );
$dirs['basedir'] = ABSPATH . 'wp-content/uploads';
$dirs['path'] = $dirs['basedir'] . $dirs['subdir'];
$dirs['url'] = $dirs['baseurl'] . $dirs['subdir'];
return $dirs;
}
}
add_filter( 'upload_dir', 'no_uploads_subfolders' );
However, when I upload an image in NextGen gallery, the resulting file is saved at /wp-content/uploads/site/2/nggallery instead of /wp-content/uploads/nggallery as I would like to.
Could you please help me force this plugin to use the root folder, as I share images and galleries accross multiple sites ?
Thank you very much !
By the way : I am using it on a staging website and therefore won’t have any public URL to share, sorry.
]]>I want to upload files to an additional upload folder. All files with ‘canada’ in their name.
I use upload_dir to create a custom upload folder:
function custom_upload_dir( $custom_dir ) {
$dir = WP_CONTENT_DIR . '/userfiles';
$url = WP_CONTENT_URL . '/userfiles';
$bdir = $dir;
$burl = $url;
$custom_dir = array(
'path' => $dir,
'url' => $url,
'basedir' => $bdir,
'baseurl' => $burl,
'error' => false,
);
return $custom_dir;
}
add_filter( 'upload_dir', 'custom_upload_dir' );
Now all uploaded files are listed in the userfiles directory.
So I thought including this does the trick:
$mystring = $_SERVER["REQUEST_URI"];
$findme = 'canada';
$pos = strpos($mystring, $findme);
if ($pos === true) {
But no!
I notice this in codex:
Using this, in conjunction with the wp_handle_upload_prefilter, you can dynamically determine which directory to upload to, based on the files you upload.
But, how can I do that?
Guido
]]>Im trying to change the path in which images are uploaded through my ACF custom field. I was able to add a folder within the “/wp-content/uploads” folder and upload to that, but what i really want is to redirect the upload path to a folder outside “uploads”. Is it possible to change the ‘basedir’ and ‘baseurl’ to something like “/wp-content/stuff/uploaded_stuff” for example? Below is the function im currently using to redirect the specific ACF uploader.
add_filter(‘acf/upload_prefilter/name=custom_field_name', 'field_name_upload_prefilter');
function field_name_upload_prefilter($errors) {
// in this filter we add a WP filter that alters the upload path
add_filter('upload_dir', 'field_name_upload_dir');
return $errors;
}
// second filter
function field_name_upload_dir($uploads) {
// here is where we later the path
$uploads['path'] = $uploads[‘basedir’].’/unique_upload_folder’;
$uploads['url'] = $uploads['baseurl'].'/unique_upload_folder';
$uploads['subdir'] = '';
return $uploads;
}
Thanks in advance!
– Charlie
https://www.ads-software.com/plugins/advanced-custom-fields/
]]>Im trying to change the path in which images are uploaded through my ACF custom field. I was able to add a folder within the “/wp-content/uploads” folder and upload to that, but what i really want is to redirect the upload path to a folder outside “uploads”. Is it possible to change the ‘basedir’ and ‘baseurl’ to something like “/wp-content/stuff/uploaded_stuff” for example? Below is the function im currently using to redirect the specific ACF uploader.
add_filter(‘acf/upload_prefilter/name=custom_field_name', 'field_name_upload_prefilter');
function field_name_upload_prefilter($errors) {
// in this filter we add a WP filter that alters the upload path
add_filter('upload_dir', 'field_name_upload_dir');
return $errors;
}
// second filter
function field_name_upload_dir($uploads) {
// here is where we later the path
$uploads['path'] = $uploads[‘basedir’].’/unique_upload_folder’;
$uploads['url'] = $uploads['baseurl'].'/unique_upload_folder';
$uploads['subdir'] = '';
return $uploads;
}
Thanks in advance!
– Charlie
]]>I’m developing a plugin that hooks into the upload_dir filter: it creates a custom upload folder in folder wp-content.
But how can I delete whole folder again, when uninstalling plugin? I would like to add this in my uninstall.php.
Guido
]]>The problem I am facing is that each document may be uploaded to different location, lets say the location is specified on the fly from somewhere ( I am using api so I get the location and file in the API POST
request).
upload_dir
filter helps in changing upload_dir if it is already known, however, in my case, I won’t know in advance the location to upload files.
Is there some way I can pass destination path to the upload_dir
filter which is only changed for my plugin and not globally?
something like following?
public function _change_upload_directory($dirs, $location)
{
$dirs['subdir'] = $location;
$dirs['path'] = $dirs['basedir'] . $location;
$dirs['url'] = $dirs['baseurl'] . $location;
return $dirs;
}
// somewhere in the code I pass the destination to upload document
add_filter( 'upload_dir', [ $this, '_change_upload_directory'], 'directory1/directory2');
]]>If I put into page or post this code:
<?php $upload_dir = wp_upload_dir(); echo $upload_dir['baseurl']; ?>
it is not working.
Could everyone shortcode for upload folder base url?
Thx,
Cavey85
https://www.ads-software.com/plugins/media-file-manager/
]]>I have a small problem with my code and funktion to show the thumbnail url it will be vry nice if some one can help me.
i have use a custom directory for my Post Type to upload the file and images.
Code: https://pastebin.com/kLRJ4Qed
and its work all very good
now i have a plugin to show user favorite post and i want to show the post thumbnail and not the url to post.
Plugin Code: https://pastebin.com/tgSHVq8c =line 68
i have use in line 68
".get_the_post_thumbnail($entry->ID)."
but its not show the image url from custom directory to show the post thumb. it show imedia.mypage.com/upload/imagename.jpg
My Qustion?
How can i show the post thumb in plugin?