July 25, 2017
file/directory operations in php
We can do numerous file directory operations in PHP. To delete a file “unlink” function is used. In below program, we can see different operations, we can uncomment code to see the behavior.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php $dir = "tasks/"; // to delete a single file unlink("tasks/temp.txt"); // to show all the text files in a directory foreach (glob($dir."*.txt") as $filename) { echo $filename . "<br>"; } //====================================================== /* // to delete all the files from a directory $dir = "files/"; foreach(glob($dir."*.*") as $v) { unlink($v); } */ ?> </body> </html>