PHP

COMMON WAYS TO MOVE FILES IN PHP

THERE IS NO "MOVE" FUNCTION IN PHP. USE RENAME TO MOVE FILES. rename("OLD.FILE", "PATH/NEW.FILE") ;

BASIC FILE MOVE

01

RENAME WILL OVERRIDE BY DEFAULT. DO A MANUAL CHECK IF YOU DON'T WANT TO.   function safemove ($src, $dest) {   if (file_exists($dest)) { return false; }   return rename($src, $dest); }

MOVE WITHOUT OVERRIDE

02

GET FILES IN SOURCE FOLDER $files = glob("FOLDER/*.{jpg,png,gif}", GLOB_BRACE);   MOVE FILES foreach ($files as $f) {    $moveTo = "FOLDER/".basename($f);    echo rename($f, $moveTo)     ? "$f moved to $moveTo"     : "Error moving $f to $moveTo";  }

MOVE CERTAIN EXTENSIONS ONLY

03

WINDOWS echo exec("move SOURCE.FILE DEST.FILE");   LINUX echo exec("mv SOURCE.FILE DEST.FILE");

COMMAND LINE MOVE FILE

04