startsWith($whiteListedPath)) { $canIDeleteFile = true; break; } } if (!$canIDeleteFile) { throw new \Exception('Cannot delete this path:' . $pathOrFile . '. Allowed paths are:' . implode(',', $whiteListedPaths)); } $exec = shell_exec('rm -rf ' . $pathOrFile); return $exec; } public static function exec($command, $argsArray = []) { $args = ''; if (! empty($argsArray)) { foreach ($argsArray as $arg) { $args .= escapeshellarg($arg).' '; } } $fullCommand = $command.' '.$args; $execOutput = shell_exec($fullCommand); return $execOutput; } }