PHP

COMMON WAYS TO DELETE FILES IN PHP

DELETE FILE unlink("TARGET.FILE");   DELETE (EMPTY) FOLDER rmdir("PATH/FOLDER/");

SIMPLE DELETE FILE

01

GET FILES $files = glob("FOLDER/*.{jpg,png}", GLOB_BRACE);   DELETE FILES foreach ($files as $f) { unlink($f); }

DELETE CERTAIN FILE TYPES

02

DATE LIMIT $keep = strtotime("YYYY-MM-DD");   GET FILES + DELETE $files = glob("FOLDER/*", GLOB_BRACE); foreach ($files as $f) {   if (filemtime($f) < $keep){ unlink($f); } }

DELETE OLD FILES

03

WINDOWS exec('del "PATH/FILE');   LINUX exec('rm /PATH/FILE');

COMMAND LINE DELETE

04

function delFolder ($folder) {   GET ALL FILES + FOLDERS   $all = glob("$folder*",  GLOB_BRACE);   RECURSIVE DELETE   if (count($all)>0) { foreach ($all as $a) {     if (is_dir($a)) { delFolder($a."/");  }     else { unlink($a); }   }}

DELETE ENTIRE FOLDER

05

  DELETE CURRENT FOLDER ITSELF   rmdir($folder); }