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 Fix HTTP Error When Uploading Images?
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- getting attachement images src and add classes
- Users can’t upload images on frontend if they haven’t got access to the wp backend
- complex restriction of items in media library
- Edit image / Delete image link
- How could I add button next to “edit image” button in “Attachment Details”
- Give attachments an archive page
- Insert Media – Attachment – Link to : Remove the “attachment page” option
- Frontend Simple Local Avatar upload
- Retrieving a custom link on an attachment
- How do i upload an image and return the image id?
- Add new media uploader at frontend for wp 3.5+
- insert post & Upload post thumbnail from the front end using ajax
- Insert custom ID into wp_get_attachment_link
- How to add attachment without uploading?
- ACF attachment custom field in rest response
- Reorder “menu order” of attachments to another predefined order
- Prevent Duplicate Attachment When Using wp_insert_post
- Change code to display image attachment page
- Attachment 0×0 size error [closed]
- Frontend Post – Allow Only Image File Upload
- How To Grab All Type Of Attachments, But Images?
- Removing width and height attributes from wp-get-attachment
- Display attachment resolution size
- Where does the gallery shortcode gets its attachments from?
- media ‘path’ issue / concern when bringing files live
- How to upload images from wordpress front-end (the first image must be thumbnail and the rest without first must be in gallery woocommerce product)
- Is it possible to share media files between multiple WordPress sites?
- How can I attach Facebook Open Graph data to an Attachment Page?
- How to implement secure frontend image upload? [closed]
- wp_upload_bits Upload Specific Sizes Only
- Set Attachment Image File URL as GUID
- Attach previously uploaded image to post – current code has unexpected results
- Upload featured image from front end using media-upload.php
- How to update the title of audio file through its attachment metadata
- Edit User Profile From Front End
- Frontend image uploading from frontend cant handle hebrew names
- Delete associated thumbnails when calling wp_delete_attachment
- Proper use of wp_get_attachment_image?
- Get title of post image is attached to
- Correct attachment size
- Upload attachment from external site
- Front-End User Profile
- Could not get attachment using wp_mail
- Looking to limit file attachment downloads
- 500 internal error at wp_generate_attachment_metadata
- How can I return multiple image attachments with wp_get_attachment_image_src
- Front end file upload returning wrong attachment url
- How to let a role handle media without post permissions
- WP_Query: attachment image in “full” size?
- How do I get just the title from wp_get_attachment_image
- i want attachment.php to return the image
- List all files from subpages
- Add videos/images preview to bbPress attachment
- PDF Upload from Input Error
- How to view exact image dimensions of a media in Admin view?
- wp_get_attachment_image_src calling wrong location
- Updating the attachment from front end doesn’t show the new change
- Get attachment URL from attachment Link in WordPress
- Send data URL string as an attachment in wp_email
- Frontend media shows “An error occurred in the upload. Please try again later.”
- How to use previous/next image link, ignoring parent posts/attachments?
- Removing delete permanently button in uploading files media
- Incomplete attachment page
- How to retrieve “custom url” from image attachment in wordpress
- list of attachments: wp_get_attachment_link works, wp_get_attachment_image does not
- Custom attachment field dissapearing
- How can I let users access a specific attachment?
- What is the most efficient way to retrieve a group of image URL’s from different attachment ID’s of a specific crop size?
- Link or button to open the media manager from frontend
- How to wrap this Link with an Image?
- How to save media-form on custom tab
- I want to edit documents on my blog without the need to download and upload files again [closed]
- Open attachments in new tab/window
- Change the next thumbnail to text