1

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,

Webkungen
  • 109
  • 3
  • 13
  • Not sure I understand your question as I have no proficiency on WP. Maybe this can help anyway : http://stackoverflow.com/a/13382331/1236044 – jbl Sep 09 '13 at 08:48

2 Answers2

0

I maintain the Custom Upload Dir-plugin for WordPress. It enables users to have context-aware upload paths (eg: folders named after the current post or author, datetimes etc). It'd be trivial to modify my filters to include your querystring.

ulfben
  • 151
  • 8
0

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.

kaiser
  • 21,817
  • 17
  • 90
  • 110