This may not be the most elegant way to do it (I’m not sure if overwriting the $_FILES global is even allowed) but this seems to work:
global $post;
if ($_FILES) {
$files = $_FILES['upload_attachment'];
foreach ($files['name'] as $key => $value) {
if ($files['name'][$key]) {
$file = array(
'name' => $files['name'][$key],
'type' => $files['type'][$key],
'tmp_name' => $files['tmp_name'][$key],
'error' => $files['error'][$key],
'size' => $files['size'][$key]
);
$_FILES = array("upload_attachment" => $file);
foreach ($_FILES as $file => $array) {
$newupload = wp_insert_attachment($file,$post->ID);
}
}
}
}
Related Posts:
- How to add media from front-end to an existing post?
- Submit post and upload image from front-end
- Uploading Multiple Attachments From Front-End With A Description
- media_sideload_image file name?
- delete attachment from front end
- Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?
- Delete attachments from Front end
- Unable to upload specific .zip file type via frontend in WordPress 4.0
- exposing attachment uploading to the front end — delicate
- How to upload image from front end and save in media library?
- How to delete orphan attachments?
- Getting ID from ajax response of async-upload.php
- rename attachments based on parent-post-title on upload
- How to retrieve alt attribute for an attachment (uploaded image)?
- Email Attachment from Form Submit
- the_time() returning wrong date/time (way in the future)
- Upload and attach to a post multiple image files [closed]
- Upload multiple image with media_handle_upload with multiple file field [duplicate]
- Undoing define( ‘UPLOADS’, ”.’files’ ); to repoint to “wp-content/uploads” folder
- How to add media from front-end to an existing post and edit file title
- wp_delete_attachment doesn’t delete image files / doesn’t work
- File was uploaded, but it is not shown on media section of the dashboard
- Using $_FILES variable into the same function for uploading images and files
- Upload unnattached image from frontend
- How To Retrieve An Image Attachment’s Alt Text?
- How to Fix HTTP Error When Uploading Images?
- How to manage attachment relationships for specific posts in WP 3.5+
- Can I add a Category Metabox to attachment?
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- Change attachment filename
- How to get attachment file name not attachment URL
- simple solution for restricting access to (some) uploads/downloads
- How to trigger a refresh in the media modal
- Get upload URL by blog ID in multisite
- Upload post thumbnail from the front end
- Get all post attachments except featured image
- Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails
- getting attachement images src and add classes
- How to restrict access to uploaded files?
- 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 can I bulk delete media and attachments using WP-CLI?
- Set Featured Image Front Frontend Form
- Disable image attachment links
- WordPress AJAX File Upload – FrontEnd
- Getting a taxonomy’s thumbnail url
- Check if post has attachments (not image)
- How to cleanly delete attachment but retain original file?
- Changing attachment urls?
- Can I use the wp media uploader for my own plugin?
- Add custom class to attachment in media library grid mode
- Are captions stored anywhere?
- Trying to hide buttons from Attachment window
- get_the_post_thumbnail() doesn’t taking style attribute
- media_sideload_image generates blank?
- Expanding new Media Uploader in WordPress 3.5
- How can I UN-attach media from a post?
- Validate alt text for attachments?
- How to upload post thumbnail while wp_insert_post?
- complex restriction of items in media library
- Saving images from Gravity Forms repeatable File Upload as post attachments [closed]
- Remove duplicate attachments
- Edit image / Delete image link
- How could I add button next to “edit image” button in “Attachment Details”
- Applying automatic link class to images embedded to posts
- How to get attachment caption (get_the_excerpt gives parent post excerpt) ?
- Is it possible to query specific WordPress Attachment files (.ppt & .pdf) and output them in a list?
- Get all posts (of any post type) an attachment is used in
- How to get all files inserted (but not attached) to a post
- What’s the database relationship between a post and its attachments
- Detect if is image unattached
- Password protect some uploaded files, so only logged-in users can view them
- How to single click to download image in single post
- wp_editor with media buttons
- Unattaching unlinked images
- How to get attachments for a specific post type?
- Give attachments an archive page
- custom fields for attachments?
- Get attachment ID of author_meta image – Attachment Metadata
- Insert Media – Attachment – Link to : Remove the “attachment page” option
- Show Post ID in “Find Posts or Pages” box in Media Library?
- URL rewrite with add_rewrite_rule and attachment_id
- Saving Custom Field in Attachment Window in WordPress 3.5
- How to set author for post AND post attachments
- front end post with multiple upload images?
- Frontend Simple Local Avatar upload
- Retrieving a custom link on an attachment
- Get attachment from post
- How to check if an image attachment exists before uploading
- How can I display custom fields value from attachment media?
- Add column for attachment file size
- how to test for attached image
- How do i upload an image and return the image id?
- Get attachments (get_posts) and WP 3.5 new uploader
- get post attachments of a particular size
- Change image link: wp_get_attachment_link
- Multi-line captions on attachments
- Make individual attachments private?
- Automatically wrap post image in div
- Gel all image from certain post type