Search code examples
phpunlink

How to Delete ALL .txt files From a Directory using PHP


Im trying to Delete ALL Text files from a directory using a php script.

Here is what I have tried.....

<?php array_map('unlink', glob("/paste/*.txt")); ?>

I dont get an Error when I run this, yet It doesnt do the job.

Is there a snippet for this? Im not sure what else to try.


Solution

  • Your Implementation works all you need to do is use Use full PATH

    Example

    $fullPath = __DIR__ . "/test/" ;
    array_map('unlink', glob( "$fullPath*.log"))