wordpress wp_handle_upload not moving the file

I assume your form is formatted kinda like this :

form action="" enctype="multipart/form-data" method="post"> //action is current post
 <input type="file" name="file">
 <input type="submit" name="submit">
</form>

And to upload the file to the wordpress upload folder using wp_handle_upload(); function you may use below code….

function handle_logo_upload($file){

require_once(ABSPATH.'wp-admin/includes/file.php');
$uploadedfile = $file;

$movefile = wp_handle_upload($uploadedfile, array('test_form' => false)); 

if ( $movefile ){
    echo $movefile['url'];
    //or return
    return $movefile['url'];
  }

}
if (isset($_POST['submit'])) {
   handle_logo_upload($_FILES['file']);
}

Leave a Comment

error code: 523