Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a function wp_handle_upload() for uploads files.

$file = $_FILES['attachment_icon-' . $i];
$upload = wp_handle_upload($file, array('test_form' => false));

what is a function for delete a uploaded file?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Use wp_delete_attachment( $post_id ) if you have used wp_insert_attachment() before.
$post_id is the attachment ID.

If you haven’t used wp_insert_attachment() a simple …

unlink( $upload['file'] );

… will do it.

share|improve this answer

there is no designated WP function, simply because you already have a PHP one, with the following syntax:


for full doc see the PHP manual:

share|improve this answer
This would leave dead entries in the database if it is already registered. –  toscho Jan 8 '12 at 21:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.