I believe the following is happening here:
- As @Luke pointed out,
wp_insert_attachment()
takes an array of post data. The format of the array you are passing to it is not correct. The keys are different. What should be stored as thepost_mime_type
, is being passed with the keytype
. Because of this, no mime type is being saved for the post. wp_generate_attachment_metadata()
is looking for the mime type so it can generate the metadata based on that. But since the mime type wasn’t saved correctly it just returns an empty array.
The solution is to do $uploadedImage['post_mime_type'] = $uploadedImage['type']
, or better yet use media_handle_upload()
, which will handle the whole media upload for you.
Example based on your code:
foreach ( $_FILES as $key => $file ) {
media_handle_upload( $key, 0, array(), $upload_overrides );
}
Related Posts:
- Extend Media Library
- How to make “Upload files”selected by default in Insert Media?
- How to show all available images in WP’s media library when using the Polylang plugin?
- Saving Media – Which Hook is Fired?
- Set limit to media upload?
- WordPress 3.5: Switch back to Old Media Uploader?
- Use a separate custom table (not posts) to handle file upload data
- Add inline uploader to plugin option page
- Insert images to post not working
- How to call WP3.5 Media Library manager?
- Settings in ‘Media > Settings’ is ignored when inserting images
- I want to replace a media file (pdf) with an updated version
- How to get all files inserted (but not attached) to a post
- Password protect some uploaded files, so only logged-in users can view them
- How to protect uploads in multisite if user is not logged in?
- Media Uploader: get deleted files
- using media uploader to select image of specific size, enforce cropper
- Trigger JS when featured image upload window is opened in admin
- Modify the array of selected images in media modal
- 3.5 media manager add CSS / JS to new ‘tab’ iframe content
- Add/change multipart_params parameter when uploading post image
- Media uploader not work properly [closed]
- http error when uploading media files
- How to change “Publish” button text for specific page
- Saving WordPress generated thumbnails in a subdirectory
- Whole bunch of errors on WP website – media upload, edit slugs, edit screen not working [closed]
- Add select field to media uploader that adds a class to the image
- Retroactively place uploaded media into -month, -year based folders?
- How To install AWS SDK for PHP in wordpress?
- wp.media add context
- Add fields to the WordPress media uploader
- How can I receive the image id using the media box?
- media sideload image not working with JPG file
- Insert Image automatically when upload finishes wordpress media uploader
- How do I modify the url of uploaded media content?
- How do I get allowed Media Library upload file extension list?
- Why would media_sideload_image() not work locally?
- Use the WP media uploader dialog for uploading a form attachment (non-admin). Offering progress and drag and drop feedback
- WordPress bug with capabilities?
- Display attachments by the ID of the post being edited in the wp.media frame (frontend)
- Media upload on WordPress changes title of image
- Media Gallery Upload photo incorrect way like glitch
- media_handle_upload() progress bar
- WordPress uploads autocreate folder every month
- Enabling users to upload files
- move_uploaded_file() not working on wordpress front end
- ‘An error occurred in the upload. Please try again later.’ for users with different roles
- wrong media url in wordpress
- Prevent small image sizes from being uploaded
- Protecting uploads not working
- making media URL secured
- How to get the return value of wp.media({ frame: ‘post’ }) in all cases?
- Is there a way to make my media files unsearchable?
- Is it possible to use media_sideload_image to upload local files?
- Attach media to post by media category
- What is the way to add additional fields to attachments in 3.5+?
- Create featured image from a remote url when creating a post
- tb_show not showing a media upload window . custom plugin
- File names are being overridden when uploading new media
- upload_max_filesize is set to 64 MB already but WordPress is still showing 2 MB
- In the media Rest API, what is “missing_image_sizes”?
- Error: The uploaded file exceeds the upload_max_filesize directive in php.ini [duplicate]
- How to fix the orientation of images when uploading via the WordPress Media Uploader? [closed]
- Migrating media files (documents only) to a fresh install and maintaining the same directory structure
- WordPress media upload issue could not insert attachment into the database
- Thumbnail images missing in WP media library
- Send media uploads to different directories
- wp_enqueue_media() and upload_mimes problem
- Reattach media after moving to another server
- Remove Media File Items From Server That Do Not Exist in Media Library
- Better solution for managing media attachments with `wp_editor()`?
- Cropping thumbnails to specific dimensions on front end post
- What if I have a large file on the server that I want the wp library to have?
- Bug: Deleting file, then uploading same file again places file in an old month folder
- Efficient way to move media folder to another folder
- Do custom post type (CPT) attachments/media store the parent post ID?
- Create multiple folders in upload media folder
- Make inline uploader (plupload) on options page upload to a specific folder
- MIME type not supporting HEIC support type in WordPress
- How to change Route respond To A specific Path?
- WordPress media has all disappeared on wp-admin but still on the server
- media file uploading
- Media Library: Remove replace images of selected author
- How to upload multiple images using WP rest API to media?
- Media files not loading
- Media files not loading
- Moving wp-content folder to public_html
- How use custom upload directories in filesystem and url based on media type or category
- Organizing the Media Library for Cleanup
- get users nickname uploaded media
- Drag and Drop Media Not Working in Windows 10 Edge Browser
- Force relative path in media library for LAN deployment
- Make custom thumbnail size image in media_sideload_image function
- Upload more than one media files with a post
- Set featured link not showing
- wordpress 3.6 media manager cropping timestamp
- Single file upload
- Can’t upload files 1MB+ [closed]
- How to disable direct media file access in nginx or ubuntu for non loggedin users?
- Image in binary in the data to WordPress media library