0

I'm using wp_upload_dir() within my plugin directory so that I can create a folder if it doesn't exist before uploading images to the directory. And for some reason it gives a 500 error during my ajax call.

my code looks like this

<?php


$upload_dir = wp_upload_dir();
$user_dir_name = $upload_dir['basedir'].'/mg_gallery';

if( ! file_exists( $user_dir_name ) ) {

  if ( wp_mkdir_p( $user_dir_name ) ) {

    $is_successful = true;
  } else {

    $error_msg = "Sorry Couldn't create directory. ";
    $is_successful = false;
  }

}
14
  • Have you enabled WP_DEBUG? Are you sure that $upload_dir contains the base_dir key? Dec 6 '16 at 21:32
  • I do have WP_DEBUG enabled. And I don't think the$upload_dir contains thebase_dir key cause when I echo it out I get nothing returned in during my request. How would I go about ensuring that it has it? Dec 6 '16 at 21:38
  • I have a feeling that it's not somehow included or capable of using the funciton but i'm not sure why that is the case or what file to include if that's the case Dec 6 '16 at 21:43
  • Do you know to read the response from the web server based on your the Ajax call? What is the exact ajax url?
    – prosti
    Dec 6 '16 at 22:11
  • the post response when I echo out $upload_dir['basedir'] is nothing. Dec 6 '16 at 22:14
-2

This was occurring because I wasn't using wp's built in ajax.

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