Uploading files in ajax is a bit tricky because it is not possible to upload files using the browser’s XMLHttpRequest object so you need to use some kind of Ajax upload plugin.
Also wp_handle_upload() is not what your using in your code its media_handle_sideload()
wp_handle_upload()– should be used for file uploads (input file field)media_handle_sideload()– should be used for remote file uploads
(input text field)
take a look at this similar question
Related Posts:
- Load minimum WordPress environment
- admin-ajax.php returns 0. How do I debug it and fix it?
- AJAX action not triggering PHP function
- How to allow to user non logged in WP system upload in media library?
- How to know what page is calling admin-ajax.php?
- How to set post_id to 0 when you upload image via Add media button. (async-upload.php)
- Ajax image upload with media_handle_upload and form.js
- wp_handle_upload returns empty error array
- Pass additional parameter with async upload
- How to disable drag-and-drop upload function in Media Library?
- Distinguish between 2 instances of admin-ajax.php
- Why is the file not uploading to the server?
- Frontend AJAX Media Upload returning 404
- How to require files in a custom endpoint
- Cannot add multiple single images at once
- How to send custom variable in Media Uploader ajax request?
- wp_enqueue_media problem
- How to cache json with wp-super cache
- Why might a plugin’s ‘do_shortcode’ not work in an AJAX request?
- Get Previous & Next posts by Post ID
- Nonces and Cache
- REST API endpoint for elasticpress autosuggest
- ajax – why multiple calls to wp_create_nonce() return same value?
- AJAX request on the frontend always returns 0 if user is not admin
- Admin Notification after save_post, when ajax saving in gutenberg
- Using ajax on categories and wordpress loops
- Cannot load admin-ajax.php. No access-control allow origin*
- Initialize JS with an ajax loaded ACF form
- Nonces and Ajax request to REST API and verification
- Accessing a random image via ajax
- Can’t seem to get wp_localize_script to work
- wp_ajax action is not running
- Ajax – gettext without a plugin
- WordPress AJAX calls not detecting language properly?
- AJAX issue – Uncaught SyntaxError when processing Zip File
- wp_verify_nonce doesn’t return true on server when it matches the nonce
- update_user_meta doesn’t work with AJAX
- wp-admin AJAX with Fetch API is done without user
- admin-ajax return error 400 for Chrome/Edge but not Firefox
- Is it safe to manually sign a user in using AJAX?
- WordPress Admin AJAX Serialize
- Why a strange discrepency between get_current_user_id() when using AJAX versus output of document.cookie?
- Loading post template that contains a nested loop with ajax
- Long Polling: Stuck in while loop
- Code run fast on a cronjob but slow with a do_action or ajax call
- update_post_meta using ajax
- Ajax comment form submit on frontpage alerts success but no insertion
- How to update Comment post meta through an Ajax call
- ModSecurity && Admin Ajax: Server locking up
- Wp mail does not work when Ajaxed to
- All AJAX requests return a 400 error
- Unable to successfully verify nonce
- Create custom POST Method URL
- Getting a variable using $post ajax back from php to js response in WP
- AJAX Call – Failed to load resource: the server responded with a status of 500 (Internal Server Error)
- WordPress is Not Setting PHP $_POST on Custom Ajax
- bulk update meta value with ajax
- javascript ajax and nonce
- Is it possible to determine whether a page is a page template by page_id in ajax call?
- Chained ajax call, second call returns 0
- How to create a form button that executes a function?
- How to stop being directed to admin.php after sending request to admin-ajax.php
- 200 return code on ‘POST /wp-admin/admin-ajax.php’ while NOT logged in
- Next Ajax call doesn’t work
- need a confirmation text to appear on email submission
- How to make pages that arent indexed for ajax applications
- Why does reCAPTCHA v3 return 0 ? In custom AJAX registration form
- admin-ajax.php 400 bad request
- WordPress Ajax Page Load to skip embedded iframe
- WordPress POST AJAX call, var_dump($_POST) NULL and AJAX response empty when inside ob_start
- Set cors header for ajax requests
- Simple AJAX code that refreshes every x seconds?
- How to keep scripts persistent during admin-ajax process when saving widget?
- Very weird bug: Ajax for non-admins
- Search function – problem with whole words
- WordPress 403 error on form submission with Ajax
- I am getting Admin-ajax.php 400 Error
- Ajax and get_template_part
- Ajax is not defined
- Get posts by category via ajax
- Adding pagination to Ajax Query
- WordPress 4.9.6 – IncludeMe & getAjax GET using wrong URL
- Create secondary Archive page format?
- check_admin_referer fails on new AJAX plugin uninstall with “Are you sure you want to do this?”
- wordpress ajax upload media not working
- How to populate data from JSON using AJAX in TypeScript? [closed]
- Weird admin-ajax.php problem
- Ajax contact form returnig 0
- Trying to send AJAX data to WordPress hook
- Can’t update WP Editor after Ajax
- Update user meta using Ajax on front end?
- retrieving page content per AJAX [duplicate]
- Posting to loop.php file
- Can’t access data from database using AJAX
- Running js in html code with same content
- How to get current_user_id from wordpress in node js?
- how can i create get request unis ajax without expecting return value
- How to use Ajax with WordPress
- Using $.ajax getting 500 error
- admin-ajax.php 400 (Bad Request) what am I doing wrong?