Mini Shell
<?php
$rootPath = realpath(dirname(__FILE__) . '/..');
require_once $rootPath . '/Portal/config/config.php'; // Use clean config file
session_start();
//require_once 'config/config.php';
$Grade = filter_input(INPUT_GET, 'Grade');
$query = mysqli_query( $conn, "SELECT * FROM student WHERE Level ='$Grade' ORDER BY Level, Full_Name ASC");
$num = mysqli_num_rows($query);
if ($num >0){
$delimeter = ",";
$filename = "Exisiting_Student_List_" . date('d-m-Y:i') . ".csv";
$f = fopen('php://memory', 'w');
$fields = array('Full_Name', 'Student_No', 'Current_Level');
fputcsv($f, $fields, $delimeter);
while ($row = mysqli_fetch_assoc($query)) {
// Create line data with empty Marks field for user to fill
$lineData = array($row['Full_Name'], $row['Student_No'], $row['Level']);
fputcsv($f, $lineData, $delimeter);
}
fseek ($f, 0);
header ('Content-Type: txt/csv');
header('Content-Disposition: attachment; filename="' .$filename . '";');
fpassthru($f);
} else {
$_SESSION['failure'] = "Students list not found";
header('location: AdminPortal.php');
}exit;
?>