Writing a plugin for Wordpress and cannot manage to set the upload folder. Found this when I googled:
$upload_dir = "images/objects" . (isset($_REQUEST['ObjectNo']) ? "/{$_REQUEST['ObjectNo']}" : "");
$plugin_dir = WP_PLUGIN_DIR . '/' . BGREAL_PLUGIN_NAME;
$plugin_url = WP_PLUGIN_URL . '/' . BGREAL_PLUGIN_NAME;
function sss_configure_upload_dir($path_data)
{
global $upload_dir;
global $plugin_dir;
global $plugin_url;
$path_data['path'] = $plugin_dir . "/" . $upload_dir;
$path_data['url'] = $plugin_url . "/" . $upload_dir;
$path_data['subdir'] = "/" . $upload_dir;
$path_data['basedir'] = $plugin_dir;
$path_data['baseurl'] = $plugin_url;
return $path_data;
}
add_filter('upload_dir', 'sss_configure_upload_dir');
On the page where the uploader frame opens, I have got the following:
$upl = wp_upload_dir();
echo $upl['path'];`
Which echoes C:\PATH\TO\HTDOCS\public_html/wp-content/plugins/bg_real/images/objects/11212
The problem is, when I open the media upload frame and uploads an image, it save into /wp-content/plugins/bg_real/images/objects
since the $_REQUEST['ObjectNo']
is missing in the async-upload
function.
I need the images organized in folders after the querystring ObjectNo
.
Any ideas? Spent hours on Google etc. and tried different approaches but none seems to work.
Thanks,