Ended up using wp_handle_upload()
, which puts MIME type into the DB automatically. See http://codex.wordpress.org/Function_Reference/wp_handle_upload
One thing to note, this function enters the file in the DB as post meta and not as an attachment. wp_insert_attachment()
would do the latter.
Related Posts:
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- simple solution for restricting access to (some) uploads/downloads
- Saving images from Gravity Forms repeatable File Upload as post attachments [closed]
- 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 check if an image attachment exists before uploading
- File upload from front-end form (as attachment) not working
- Add suffix to filename of uploaded images
- Check if image exists before uploading with media_sideload_image()
- Add a YouTube or Vimeo video as a post attachment?
- How can I save the original filename to the database?
- ACF attachment custom field in rest response
- How to solve: An error occured in the upload
- Images not being generated at correct size
- How to manage a big collection of files with wordpress?
- Use the WP media uploader dialog for uploading a form attachment (non-admin). Offering progress and drag and drop feedback
- Rename attachment filenames to attachment ID on upload
- What is the way to add additional fields to attachments in 3.5+?
- How to edit attachment with media-upload.php?
- Upload iPhone video clips to blog via native WP app
- How to load attachment in media library for current user?
- How does WordPress decides how many sizes of an image to create?
- Upload and attach to a post multiple image files [closed]
- wp_generate_attachment_metadata for non-images files
- Insert attachments from custom uploader into post (regular uploader style)
- PDF Upload from Input Error
- Do custom post type (CPT) attachments/media store the parent post ID?
- Using unzip_file() to get contents of file
- What is wrong with my wp_insert_attachment code?
- Adding attachment custom field metadata to TinyMCE tag
- Updating the attachment from front end doesn’t show the new change
- Set attachment category from file name on upload
- “Could not write file” error in wp_upload_bits function
- _d_improd_ directory in uploads breaking site images
- Check if author or uploader id of the attachment(uploaded) image is match?
- Limit attachment caption characters
- controlling whether upload is attached to post or not
- How to force attachment size for every post
- Attachment Metadata not updated while uploading audio files
- Upload file to front-end form and send as email attachment
- Limit number of uploaded attachments of specific context
- How do I protect my uploads?
- How do I update attachment urls after changing site domain
- How to properly move media files and update data?
- Get Specific Files (Only Specific Extension Type All Files in Loop ) from Media
- All uploaded files using wp_mail() renamed to tmp_name
- Plupload Intergration in a meta-box?
- How to Fix HTTP Error When Uploading Images?
- Trigger refresh for new media manager in 3.5
- Physical organization of wordpress media library (Real Media Library plugin)
- Can I upload media to a specific folder?
- wp_upload_dir how to get just the directory name .
- How to generate thumbnails when needed only?
- Limit image upload to one and disable audio, video and other document file types to upload
- How to add new tab to media upload manager with custom set of images?
- No Thumbnails Generated
- Media files exist in upload folder but not showing up
- How to Require a Minimum Image Dimension for Uploading?
- How to upload files straight to S3 without using local storage? [closed]
- Extend Media Library
- How to make “Upload files”selected by default in Insert Media?
- WordPress 3.5: Setting custom “full URL path to files” in the Media Library?
- Get $image_id after uploading with media_sideload_image()
- Submit post and upload image from front-end
- what happens to existing media files when I switch to year/month directory structure format?
- Reject upload of wrong-sized images using the Media Uploader
- WordPress Media Uploader events
- Get upload URL by blog ID in multisite
- How to show all available images in WP’s media library when using the Polylang plugin?
- how to upload and allow downloads of .mobi and .epub formats
- Upload post thumbnail from the front end
- Allowing WebP uploads?
- Give users a maximum upload capacity; limit the number of files a user can upload OR limit the number of files per upload
- How to add a custom field to the media screen (image/gallery)?
- Can’t upload media, permissions are correct
- How to assign multiple file-mime-types to extension?
- Saving Media – Which Hook is Fired?
- Set limit to media upload?
- How to restrict access to uploaded files?
- Is it possible to reorganize the WordPress uploads directory?
- WordPress 3.5: Switch back to Old Media Uploader?
- Save camera info as metadata on image upload?
- Media upload finished hook
- Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
- Users can’t upload images on frontend if they haven’t got access to the wp backend
- How to upload SVG in WordPress 4.9.8?
- How Can I Organize the Uploads Folder by Slug (or ID, or FileType, or Author)?
- How can I batch delete all unattached images with WP-CLI or other automated process?
- Create image formats with different qualities when uploading
- Rename files during upload using variables
- upload_async.php returns 500 error
- Which filters or actions to use after a media upload and delete?
- Organize uploads by year, month and day
- wp_delete_attachment doesn’t delete images in wp-content/uploads/
- Display attachments by ID in a wp.media frame
- Force WordPress 3.3 to use Flash uploader
- Use a separate custom table (not posts) to handle file upload data
- Disable image attachment links
- Upload folder is not writable, even when permissions are correct
- Different upload directory based on post type in a theme