Friday, June 3, 2016

How to delete latest file in folder in php

How to delete latest file in folder in php:

For delete the latest file in php we have to use following code.

           $filePath = 'path/of/folder';
            $files = glob($filePath . '/*.*');
            array_multisort(
                array_map('filemtime', $files),
                SORT_NUMERIC,
                SORT_ASC,
                $files
            );
            exec("rm -rf " . $files[0]);


Thanks

No comments:

Post a Comment