trying to use wp_handle_upload with ajax

You need to include a few files to get wp_handle_upload to work, and i have a function just for that :

function My_wp_handle_upload($file_handler,$overrides) {

  // check to make sure its a successful upload
  if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();

  require_once(ABSPATH . "wp-admin" . '/includes/image.php');
  require_once(ABSPATH . "wp-admin" . '/includes/file.php');
  require_once(ABSPATH . "wp-admin" . '/includes/media.php');

  $upload = wp_handle_upload( $file_handler, $overrides );
  return $upload ;
}

so after you add this function to your file just change your call from :

$file = wp_handle_upload($data['MoobLogoUpload'], $overrides);

to:

$file = My_wp_handle_upload($data['MoobLogoUpload'], $overrides);

Update

Just remembered that you must use an ajax upload solution like:

  • JQurey form plugin
  • Uplodify
  • SWFUpload

any other or submit by iframe since it is not possible to upload files using the browser’s XMLHttpRequest object