February 2008
Intermediate to advanced
216 pages
4h 33m
English
To remove a file on Unix, use the unlink() function:
<?
if (unlink("file.txt")) {
echo "file.txt deleted.";
} else {
echo "file.txt: delete failed.";
}
?>You need the proper permissions to delete a file, of course. However, the biggest danger here is that you can delete a file that you didn't mean to delete. When you delete a file in Unix, it's gone; there's no undelete or trash can. The only way you might get something back is from your system administrator's backups.
And be careful here if you plan to have user actions deleting files. This is dangerous for every reason discussed and for every other file operation discussed so far.
Read now
Unlock full access