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
- jQuery’s .on() method combined with the submit event
- Why use admin-ajax.php and how does it work?
- Why is die() used at the end of function that handles an Ajax request?
- Making my AJAX powered WordPress Crawlable
- Why is a 500 error generated by admin-ajax.php not going into the Apache error log?
- admin-ajax.php doesn’t work when using POST data and Axios
- Custom Form with Ajax
- How to process ajax requests correctly using ajax plugins
- Add item to media library from blob or dataUrl
- How is it possible that the function of the test page works, but it does not go live?
- jQuery Autocomplete not working with wp_localize_script
- Ajax returning correct data BUT at wrong place
- get_posts empty when called via Ajax
- admin-ajax.php mixed content
- WP-API and Basic Auth returning 403 on POST but not GET
- Is there a hook to process a backbone restful PUT request inside wordpress?
- How to localized one js file for different actions?
- WordPress Ajax Problems
- trying to use wp_handle_upload with ajax
- Force redirect not logged in user to (wp-login.php or wp-admin) for specific page
- How can I access the Header of and ajax response from the rest API
- Getting back to ajax search results from a page
- Updating a checkbox value to database for specific row in table
- WordPress Ajax Not Working ( Custom Admin page)
- WordPress ajax success response
- Admin WP List Table Columns Missing
- (updated) How to add AJAX error handling to a (fully) custom registration form?
- Load JavaScript from a post that’s loading into Fancybox via ajax
- Gravity form Load By Ajax Cannot Submit – Error 400
- wordpress admin ajax url rename
- Image upload via FormData API and AJAX is not working ($_FILES always empty)
- rest_no_route custom route
- Using infinite scroll ajax load more with search parameter
- Cache wp-json/posts without a plugin?
- How to implement secure frontend image upload? [closed]
- What is the best way to do MyAjax error and success handling?
- Gravity Forms closes my popup on Validation Error [closed]
- infinite-scroll for 2 fixed height containers
- “Loadmore” button is not working in buddypress [closed]
- Uncaught ReferenceError: the_ajax_script is not defined . How is this not defined?
- Right way to include blog-header.php?
- AJAX action through direct link
- Ajax call on new site with jupiterx theme getting 400 response [closed]
- I can’t get a return value from Ajax
- WordPress AJAX return 0 – My case
- Creating an auto result search bar
- update_option is not saving an array, but saving the string ‘Array’
- Ajax call in wordpress not working for subscriber user
- Ajax call in WordPress – unable to display the data on the page
- What WP-API authentication method should I use to interact with anonymous / not-logged visitors?
- How to call ajax in plugin file
- Get title and featured image using Ajax
- javascript onClick update user_meta from jquery.ajax
- How to ignore WP_ERROR caused by “get_the_excerpt” method in an AJAX call?
- WP_Query is not received in Ajax
- My function containing a mysql query launched by ajax is not working in wordpress. What am I missing?
- How do I mitigate replay attacks when talking about actions that shouldn’t happen twice?
- Updating Jquery object with newly created elements after AJAX call
- wordpress ajax search posts
- Ajax call from Plugin using Class
- enqueue style using admin-ajax.php
- Ajax by worpdress affects called jquery inside template file
- AJAX form not working, still reloads on submit
- Call public static method from ajax ‘wpcf7_mail_sent’ hook
- Update user meta via ajax from frontend, saving issue
- How to get the admin page slug using wp_loaded hook?
- Edit user meta on front-end via AJAX
- Having a self updating list
- What is the best way to handle Ajax image upload on front end?
- Unexpected WordPress search results
- WordPress Get Header and Footer using in Admin Area
- Tie the sending of an ajax request to WordPress hooks
- AJAX: admin-ajax.php is adding extra content to my script’s response – how to exclude header, footer, etc.?
- Is custom behaviour possible when asynchronously uploading?
- ajax page template
- apply_filters, EMBEDS and AJAX not a friends? [duplicate]
- Using Javascript Callback from plugin in a theme
- Why does my Ajax Get request give a 400 bad request?
- Translating wordpress foreach to ajax
- AJAX loading with custom parameters
- Adding custom fields to Wired Impact Volunteer Management Plugin
- Placing ajax actions in different class
- randomly get 400 error while user is logged in wp_ajax