WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've used this tutorial to build an option page form with Ajax.

Now, i want to use the wp_handle_upload to upload an image. i tried this http://pastebin.com/35HW8RSZ but with no success.

help will be appreciated. Asaf.

share|improve this question

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);


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


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

share|improve this answer
up vote 1 down vote accepted

I found a very simple solution here. It Exceeds any external Ajax solution, in my opinion.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.