permission($radice) && !empty($_GET["token"]) && !empty($_GET["modulo"]) && !empty($_SESSION["reportManagerData"][$_GET["token"]][$_GET["modulo"]])) { $error = false; $data = $_SESSION["reportManagerData"][$_GET["token"]][$_GET["modulo"]]; $firstLine = [array_keys($data[0])]; $data = array_merge($firstLine,$data); header('Content-Description: File Transfer'); header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=\"export.csv\""); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header("Expires: 0"); foreach($data AS $row) { array_walk($row,function(&$item) { if (is_numeric($item)) { $item = str_replace(".",",",$item); } else { $item = strip_tags($item); $item = convert_to_utf8($item); $item = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $item); $item = preg_replace( "/\r|\n/", "", $item); $item = str_replace('"', '""', $item); } return $item; }); echo "\"" . implode("\";\"",$row) . "\"".PHP_EOL; } } if ($error) { header('HTTP/1.0 403 Forbidden'); die(); }