How to delete-remove file with PHP
Feb 23, 2009
Author: Developer
PHP function unlink () is delete file if the filename like argument is valid.
Example
In this example at beginning we have user function who try to delete file
and write result message if file is deleted.
1- <?php
2- function delete_file( $file ) {
3-
4- if ( unlink( $file) ) {
5-
6- echo (“ File $filename is deleted “);
7-
8- }else {
9- echo ( “File $filename can not be deleted“);
10- }
11- }
12- ?>
13- <html>
14- <head>
15- <title>Deleting file example</tile>
16- <body>
17- <?php
18- $file = “/var/www/test/images/test.jpg“;
19- delete_file($file);
20- ?>
21- </body>
22- </html>
views 1979



