I use exec() to execute this a cp UNIX command:
$path = "/var/www/copy_dir/";
$pp = "cp -R /var/www/top_folder/mid_folder/base_folder/".$user_id."/* ".$path;
exec($pp, $ax, $ay);
if($ay === 0) {
return "done";
} else {
return "error";
exit;
}
This works fine, it does what I need, however, I want to execute rm -rf (or other more safer way to clear the contents of the dir) on the $path first before copying. Can I combine it on my current $pp?
Yes, just use a semicolon if you want to unconditionally execute both commands. Or (as mentioned by g13n) double ampersand, which will only execute the second command if the first one succeeds.