Take the 2-minute tour ×
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
add comment

2 Answers

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
add comment

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

    <?php
    $filename="MyFile.txt"
    unlink($filename);
    ?>

for full doc see the PHP manual:

http://php.net/manual/en/function.unlink.php

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

Your Answer

 
discard

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.