Deleting files with unlink()

To delete files, simply pass a filename string as the only parameter to unlink(). Note that unlink deals only with files - to delete directories you need rmdir().

if (unlink($filename)) {
"Deleted $filename!\n";
    } else {
"Delete of $filename failed!\n";

Author's Note: if you have a file opened with fopen(), you need to fclose() it before you call unlink()


Next chapter: Temporary files >>

Previous chapter: Copying files with copy()

Jump to:


Home: Table of Contents

Follow us on or Twitter

Username:   Password:
Create Account | About TuxRadar