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

PHPunlink

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.

Best Answer

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

Example

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