Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers 2

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

share|improve this answer
add comment
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
add comment

Your Answer

 
discard

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.