Recipe 24.5. Deleting a File

24.5.1. Problem

You want to delete a file.

24.5.2. Solution

Use unlink( ), as shown in Example 24-16.

Deleting a file

<?php $file = '/tmp/junk.txt'; unlink($file) or die ("can't delete $file: $php_errormsg"); ?>

24.5.3. Discussion

The function unlink( ) is only able to delete files that the user of the PHP process is able to delete. If you're having trouble getting unlink( ) to work, check the permissions on the file and how you're running PHP.

24.5.4. See Also

Documentation on unlink( ) at

PHP Cookbook, 2nd Edition
PHP Cookbook: Solutions and Examples for PHP Programmers
ISBN: 0596101015
EAN: 2147483647
Year: 2006
Pages: 445

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: