Custom upload dir “on the fly” in WordPress 3.6?

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:

Read More
$upl = wp_upload_dir();
echo $upl['path'];`

Which echoes C:PATHTOHTDOCSpublic_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,

Related posts

Leave a Reply

2 comments

  1. In case someone stumbles upon this, you can use the UPLOADS directory constant from within your wp-config.php file:

    // before including wp-settings.php
    define( 'UPLOADS', WP_CONTENT_DIR.'/my-upload-target' );
    

    That’s it. The rest gets cared about automatically.