To delete a file from the file system, you can use something like this attached to an AJAX hook that is called by jQuery:
function ajax_remove_image() {
check_ajax_referer( 'image_removal', 'image_removal_nonce' );
if ( ! $_POST[ 'confirm' ] )
exit( 'false' );
$uploads = wp_upload_dir();
$upload_dir = $uploads[ 'path' ];
$file = strpos( $_POST[ 'file' ], "https://wordpress.stackexchange.com/" ) !== false ? $_POST[ 'file' ] : $upload_dir . "https://wordpress.stackexchange.com/" . $_POST[ 'file' ];
$attachment_id = null;
@unlink( $file );
if ( ! file_exists( $file ) )
exit( 'true' );
else
exit( 'false' );
}
This code comes from a plug-in that I am currently working on (source), so you may have to adjust it as necessary.
Related Posts:
- Using media-upload.php to upload mp3 via custom fields
- Extend WP Customizer to make multiple image selection possible
- Saving Custom Field in Attachment Window in WordPress 3.5
- WordPress custom upload field error
- limit amount of photos uploaded per cpt post
- Metabox with multiple fields added by user and upload box
- Metabox image upload and custom field
- Custom image sizes for custom field media uploads
- wp_handle_upload error “Specified file failed upload test” but still creates attachment?
- Insert attachment ID in custom field from media uploader
- How to save media files under custom folder without changing wp-config.php or changing media settings
- How can I store a file in the database in the same way WordPress and ACF do?
- How do i save and retrieve custom attachment meta?
- Is there a simpler version of WP Media?
- Client PDF Upload (Catalogue) – Automatically update link to PDF
- How to add upload video option in wordpress for user?
- Uploading PDF using Media Uploader
- Select multiple images from custom field
- WordPress Media Uploader custom Javascript not working
- How to use media upload on metabox post page without breaking TinyMCE?
- Front-End User Profile
- Image upload and path to custom field
- Problem uploading different files as custom fields with front end post form
- How do I upload file through custom field, save it to database and get it
- Can you generate a featured image from two images from custom fields?
- want to add video upload option for front end user
- display custom media folders to wordpress media popup
- Custom Meta Boxes and Fields for WordPress: Change directory upload based on user-edit page
- Change path to child of page when uploading image via custom field
- How can I create more “create attachment” custom field – any idea?
- Upload image to wordpress
- Multiple image uploader under editor?
- unlink() doesn’t delete the uploaded file
- Save Custom Meta Value on Media Upload
- WP_Query – Order results by meta value
- Custom query with orderby meta_value of custom field
- Orderby meta_value only returns posts that have existing meta_key
- How to enable revisions for post meta data?
- Any way to add custom options to Gallery Settings?
- Including custom fields in search?
- Sort posts by custom field numeric value using dropdown
- How to position a custom field before the editor
- How can I display all values of a custom field from posts with a certain value of another custom field or from certain post types?
- searching in custom meta field
- How to add upload field in a custom taxonomy?
- Display thumbnail from custom field
- Bulk move (or copy) from a custom field to the post content?
- Getting Custom Field data from a page hierarchy
- Custom contact form 7 select with custom values [closed]
- Problem with adding exta field in metabox in custom post type
- Add WYSIWYG to Image Description field
- Calling custom profile fields?
- Show ACF fields only on certain page in the backend
- Performance of storing multiple meta fields vs one JSON encoded field [duplicate]
- Create Multiple File Upload Metabox in WordPress
- WP_User_Query pulling ACF to loop
- How to disable plupload completely from latest wordpress 3.6 and make browser upload default
- how to put a custom field value in variable
- Custom Metabox Not Saving
- Create custom fields as image uploads [duplicate]
- Advanced Custom Fields dynamic update_field
- Custom Profile Fields move from BBpress to BuddyPress
- How can I output a list of values for a custom field, and posts with those values?
- Manipulate javascript code from custom made admin page menu
- Add additional ‘description’ field for defined roles / role metadata?
- Change the main loop WordPress impact on the server?
- How to get categories with posts by custom field value?
- Walker class for sub-menu with ACF fields
- Display custom field value part by part?
- Add custom fields to existing posts (admin pages)
- How do i get the attached images with custom value checked?
- How to disable Edit Post and Allow only Custom Field?
- Convert attachment ID into url?
- Cannot save underscore custom fields in one wordpress installation using xmlrpc and underscores
- Custom Fields Question
- do_shortcode close
- How do I convert all custom_field php timestamps in the database to js timestamps?
- Custom Query Fields – Altering Meta Value
- Adding re-type email and check it if the email match
- show a specific metabox dependent on the page template
- excluding posts by an ACF field in pagination
- Search & column order by meta value in admin
- Exclude URL’s from sanitize_html_classes
- Best way to insert a list of links into a post outside of the_content
- How to add a post’s view count into the WordPress API response
- How can I ‘check’ the “custom fields” box from the Screen Options?
- How to get all wp_posts in wordpress fetched from database
- Update custom field on the fly
- automatically add custom fields to post title
- Custom Fields Permalink Plugin not observing hyphens
- will wp_insert_post write a new custom field to the database?
- How to repeate custom field group with bulk image field
- ACF – Compare user and post data
- Extra text’n’image field in a page
- Get first URL from custom field, download and set as featured image on post publish
- How to add an option to admin to add image that could be used as header?
- How to query posts that have certain post meta keys, and sort by meta key and/or value
- Add image custom attribute [closed]
- Foreach giving one too many list items, how can I remove the last empty line?
- Add custom fields to specific menus